I have the following input:
<input type="submit" name="next" value="Next">
How would I make this item un-clickable via jQuery? (i.e., it may only be clicked after certain validation criteria are met) ?
Here is a follow-up to this question: Make a submit clickable after validations are met
I have the following input:
<input type="submit" name="next" value="Next">
How would I make this item un-clickable via jQuery? (i.e., it may only be clicked after certain validation criteria are met) ?
Here is a follow-up to this question: Make a submit clickable after validations are met
Share Improve this question edited May 23, 2017 at 12:17 CommunityBot 11 silver badge asked May 24, 2012 at 3:01 David542David542 110k203 gold badges564 silver badges1k bronze badges 4 |4 Answers
Reset to default 82 Demos Demo 1 click here: or Demo 2 click here:
so all you will need is to check if the validation is done correctly of not.
i.e. if (notValid)
chuck in the code below and that will disable the button. or better yet start with the disabled next
button.
To enable you can set the property as false, I am sure you get a good idea, else provide more code; I am happy to help you further. B-)
Hope this helps!
$("#submit").prop('disabled', true);
OR
$("input[type='submit']").prop('disabled', true);
$('input[name="next"]').prop('disabled', true);
you can use:
$("input[type=submit][name='next']").attr("disabled", "disabled"); // unclickable
$("input[type=submit][name='next']").removeAttr("disabled"); // clickable
Disabling an input element does not consistently prevent click events or their further propagation across browsers.
Regardless, it would be appropriate to simply return false
if the validation fails, so that an action (i.e. a form submit) is not performed. This will prevent form from being submitted, and since the click handler is still executed you would be able to provide details to the user about why the submission failed:
$("#submit").click(function(){
var isValid = true;
/*perform validation checks, changing isValid value to false when needed*/
return isValid; //will return false if validation fails etc.
});
disabled="disabled"
in your markup, and remove it once the validation has run successfully? – ahren Commented May 24, 2012 at 3:02