I want to read the value that is in the input box and based on that, create (with PHP in the same file) some dropdown boxes. After trying several hours I can't find a way to do this.
The HTML Input Field
<input type="text" onblur="sendData(this.value)" name="ingr_count" id="ingr_count" pattern="\d*" />
I have this JS/AJAX to read the value and post it in the PHP
function sendData(obj) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
alert(obj);
// Do stuff when script returns
}
}
xmlhttp.open("POST","script.php?count=" + obj.value + "&t="+Math.random(),true);
xmlhttp.send();
}
I also have this PHP to read the value
$src1= $_POST['count'];
echo $src1;
Commenting out everything bellow var xmlhttp; and alerting the obj will alert the obj but if I uncomment it won't even alert the value! :O .