Having a problem with simple AJAX call that checks if checkbox is checked. At the moment, no matter if the checkbox is checked or not, it would print "not checked". I've tried changing "POST"/"GET" methods in he PHP code, but the result is same, i dont know why? any ideas?thanks!
#test.html
<html>
<head>
<script type="text/javascript">
function load()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("div1").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","checkbox.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="checkbox" value="value1" name="check1"/>BOX 1</input>
<br>
<input type="checkbox" value="value2" name="check2">BOX 2</input>
<br>
<button type="button" onclick="load()">Run</button>
<div id="div1"></div>
</body>
</html>
#checkbox.php
<?php
if(isset($_GET['check1'])
{
echo "checked";
}
else
{
echo "not checked";
}
?>