Fire Event Immediately if Checkbox is Checked, Calling Server-Side PHP [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
These are my checkboxes:
<input type="checkbox" name="cb1" onclick="check(this)">Batas Wilayah</input><br>
<input type="checkbox" name="cb2" onclick="check(this)">Lokasi Masjid</input><br>
This is my PHP code:
<?php
function check() {
if ($('cb1').is(":checked")) {
$.getScript("batas.php");
} elseif ($('cb2').is(":checked")) {
$.getScript("daftar.php");
}
}
When cb1 or cb2 are checked, I want to immediately call a server-side PHP script with the form data. Can anyone point me in the right direction?

jQuery.getScript is specifically for loading javascript. In theory it should still work fine but using a AJAX jQuery.get request is worth a shot.
$.get("batas.php", function( data ) {
alert(data);
});
In the above code data is the data returned from the php script.

Related

How to disable/enable text box depends on Enum? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am working in MVC C#. I have a table with Enum values. I got 2 conditions in Enum as On and Off. I want my text box to be Enabled during On and Disabled during Off. How to do this ? kindly help.
My text box as follows:
<div ><p class="form_text1">Start</p> <input type="text" id="EditStart" name="EditStart" class="form-control">
</div>
If you want a bit more of a generic approach, you can do this through C# instead of JavaScript. However, I am unsure how you are getting this enum so my answer might not work. Hope this helps.
public static MvcHtmlString EnumTextBox(this HtmlHelper<TModel> htmlHelper,
YourEnum enum)
{
object attributes = null;
if(enum == YourEnum.Off)
{
attributes = new
{
disabled = "disabled"
};
}
return htmlHelper.TextBox("YourTextBoxName", null, attributes);
}
Note: I did not test this, just wrote it out from head.

Unable to get data from dynamically created textfield in javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a small project where i created text fields based on user input.
$('#arraySizeButton').click(function() {
var arraySize = $("#arraySize").val();
if(arraySize=='') {
alert("Enter Some Text In Input Field");
}else{
var count = arraySize;
var html = [];
while(count--) {
html.push("\<input type='text' id='inputTextField", count, "'>");
}
$('#inputTextFieldsarea').append(html.join(''));
}
});
I want to create a dynamic program based on above code and retrieve data from textfields to an array. Appreciate your help.
Did you mean this?
html.push("<input type='text' id='inputTextField"+count+"'/>");
What you should do is add a [] to the name of the input, to let the html form know that this is an array.
You should do something like that:
html.push("\<input name='field[]' type='text' id='inputTextField", count, "'>");
And using php to get the content of all the POSTed fields you could simply check
$_POST['field']
which is an array.
EDIT: IF you want to do this using jquery as you stated in your comment, then you could do it like that:
$('[id^="inputTextField"]').each(function() {
alert($(this).val());
});

jquery cookies / javascript cookies [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm have planned to design a jewelry website with add to cart option. but i still don't know how to keep the selected items on the cart even after refreshing the page through jquery. so if anyone knew please provide an step by step example or tutorial.
You can use a simple JQuery get method which links to a PHP file which adds the product to the Site cookies; when you want to view the cart, explode the cookie.
An example:
$(document).ready(function(){
$("#product").click(function(){
// However you want to get the item ID
var itemID = document.getElementById("productID").value;
$.get("/inc/addtocart.php", { item: itemID }, function(data){
document.getElementById("result-sec").innerHTML=data;
});
});
});
Your PHP file will look like this:
if(isset($_GET['item'])){
$_COOKIE['cart_ids'] = $_COOKIE['cart_ids'] . '::' . $_GET['item'];
}
To view your cart items, simply:
$all_items = explode("::", $_COOKIE['cart_ids']);
foreach($all_items as $item):
echo $item . "<br />";
endforeach;

How to populate drowndown box using spring+hibernate,jsp [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am new in this world...so please help..I want idea from u people...I have 4 dropdown list ..and I wanted to populate select box on selecting another selectbox2 .... using database values....so how should I proceed ..i need your help...and i have already created the database for that...and I am good with database....so please help me..forward me some link also..I have short span of time..within that i have to complete..please help.
In Spring 3.0 you can populate values in the dropdown as follows:
#ModelAttribute("webFrameworkList")
public List<String> populateWebFrameworkList() {
//Data referencing for web framework checkboxes
List<String> webFrameworkList = new ArrayList<String>();
webFrameworkList.add("Spring MVC");
webFrameworkList.add("Struts 1");
webFrameworkList.add("Struts 2");
webFrameworkList.add("JSF");
webFrameworkList.add("Apache Wicket");
return webFrameworkList;
}
In JSP
<form:select path="favFramework">
<form:options items="webFrameworkList"/>
</form:select>
Now you can modify the logic as per your requirement that you want.

Change text next to checkbox IF checked. HTML + JS or jQuery [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I just want to use a simple checkbox, for example, a checkbox with 'Please check this' next to it, then when it's clicked the text changes to 'Checked'
I've been looking all over for a simple solution, but struggling and can't figure it out - despite the simplicity.
Can somebody help me?
Using jQuery:
$('#boxid').click(function() {
if ($(this).is(':checked')) {
$(this).siblings('label').html('checked');
} else {
$(this).siblings('label').html(' not checked');
}
});
and in your HTML:
<input id="boxid" type="checkbox"><label for="boxid">not checked</label>
EDIT:
Working fiddle: http://jsfiddle.net/zpzxM/
JavaScript:
function changeText(id){
if ($('#'+id).is(':checked')) {
$('#'+id +"+span").html('Checked');
}else{
$('#'+id+ "+span").html('Please check this.');
}
}
CSS:
<input type="checkbox" id="123" onclick="changeText(this.id);"><span>Please check this.</span>
"live Example"

Categories

Resources