I am trying to use something like this in my code but having no luck...
function captcha(data) {
var httpxml;
try {
// Firefox, Opera 8.0+, Safari
httpxml = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
httpxml = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpxml = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateck() {
if (httpxml.readyState == 4) {
document.getElementById("cap_error").innerHTML = httpxml.responseText;
var result = httpxml.responseText;
if (result == 'Error..try again') {
document.getElementById("regSubmit").disabled = true;
}
}
}
var url = "includes/captcha.php";
url = url + "?datacap=" + data;
url = url + "&sid=" + Math.random();
httpxml.onreadystatechange = stateck;
httpxml.open("GET", url, true);
httpxml.send(null);
}
Edit:
My submit button is:
<input type="submit" value="Submit" id="regSubmit" name="Submit"/>
When ajax function returns 'Error..try again' regSubmit button should be disabled. But this function is not working for my right now.
if (result == 'Error..try again')
{
document.getElementById("regSubmit").disabled = true;
}