I am populating combobox on checkbox checked or not click event.
Here is code. I am not solving the bug, JS runs on chrome but not in both IE and Firefox.

checkbox

<input type="checkbox" onclick="selectinactivebatch(this.value);" id="inactive_batch" name="inactive_batch" <?php if(isset($_POST)) echo "checked";?>>

AJAX Code

function selectinactivebatch(checkboxvalue)
{


var check;
if(checkboxvalue=='on')
check=1;
else
check=0;
alert(check); // Always showing value 1
xmlhttpbatch=GetXmlHttpObjectbatch(this.value);
if (xmlhttpbatch==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="selectBatch.php";
url=url+"?action=inactive_batch_collection";
url=url+"&val="+check;
xmlhttpbatch.onreadystatechange=stateChangedbatch;
xmlhttpbatch.open("GET",url,true);
xmlhttpbatch.send(null);
}


function GetXmlHttpObjectbatch()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}


function stateChangedbatch()
{
if (xmlhttpbatch.readyState==4)
{
document.getElementById("txtBatch").innerHTML=xmlhttpbatch.responseText;
}
}

Recommended Answers

All 3 Replies

Change checkboxvalue=='on' to just checkboxvalue .

<input type="checkbox" onclick="selectinactivebatch(this.value);" id="inactive_batch" name="inactive_batch" <?php if(isset($_POST)) echo "checked";?>>

Where is the value of that checkbox ? You must have already put that checkbox value. Like:

<input type="checkbox" onclick="selectinactivebatch(this.value);" id="inactive_batch" name="inactive_batch" value="<?php echo $value; ?>" <?php if(isset($_POST['inactive_batch'])) echo "checked";?>>

Hope this help.

Yes, probably you mean this.checked? If you change that and what I said before, it should work (as long as you mean checked, not value).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.