1

Using Jquery, how to disable a submit button via its ID? I have tried many codes, but failed.

$("#sign_up").attr('disabled', 'disabled');

here is another one i tried:-

$("#sign_up").attr('disabled', true);

Note: I have included jquery library: //ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js
It will be very nice of you if you provided a fiddle :)

1
  • ... and it should suffice, unless you invoke this line before #sign_up element appears in DOM. Is this line called in $(function(){ ... }) block? Commented Apr 28, 2013 at 16:52

3 Answers 3

1

jQuery documentation states that "The .prop() method should be used to set disabled and checked instead of the .attr() method." - http://api.jquery.com/prop/#prop-properties

disabled is a property and it needs to be addressed that way, using the $(element).prop() method. I have created a working jsFiddle for you: http://jsfiddle.net/tb5Xh/1/

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

Comments

0

it should work just fine.

$("#sign_up").attr('disabled', 'disabled');

check the fiddle. http://jsfiddle.net/qb2vH/

check if you have added the jquery library correctly.

1 Comment

While this will work, jQuery documentation states that "The .prop() method should be used to set disabled and checked instead of the .attr() method." -api.jquery.com/prop/#prop-properties
0

Users may still be able to submit forms by pressing enter in a form field.

If you want to stop the whole form being submitted, you could intercept the submit event of the form:

$("#sign_up").closest('form').submit(function(e) {
    e.preventDefault();
    return false;
});

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.