OK so I am trying this whole AJAX thing and I hope I am doing this correctly. Here's the code:
function checkDate(str) {
if (str == "") {
document.getElementById("dateMessage").innerHTML = "";
return;
} else {
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("dateMessage").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","scripts/checkDate.php?date="+str,true);
xmlhttp.send();
}
}
function registerBTN(str) {
if (str == "") {
document.getElementById("register").innerHTML = "";
return;
} else {
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("register").innerHTML = xmlhttp.responseText;
}
}
var enableBTN = <?php echo $_SESSION["date"] ?>
if (enableBTN) {
$("register").removeAttr("disabled");
}else{
$("register").attr("disabled", "disabled");
}
}
}
So the PHP calls checkDate()
just fine and it works.
Here's what I (think) I want to do.
1) In checkDate()
just after the xmlhttp.send()
I want to call registerBTN
. I am not sure how to do that.
2) I cannot confirm if registerBTN
works at all. It should enable or disable based on the PHP session variable which is controlled in checkDate.php
Please let me know if you need any further information from me.
Thank you for any help you can give!