0

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;
}
1
  • Explain in more detail what you want your script to do. I'm not entirely sure what you mean. Commented Sep 5, 2009 at 12:43

1 Answer 1

1

This is what we have in our app:

document.getElementById('buttonId').disabled=true;

And it works.

Two things:

1 - Make should you clear your browser cache after you change your javascript.

2 - Put an alert before you disable your button to make sure you are getting into your 'if' statement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.