How to disable submit button using jquery?

I have a checkbox that needs to be checked so that the form can be submitted.

Therefore, I set the attribute of the disabled submit button to “disabled”. Then I tried to attach a flag to it so that it turned on / off the submit button. This does not work:

$('input[type=checkbox]#confirm').click(function() { if ($(this).is(':checked')) { $('#submitButton').removeAttr('disabled'); } else { $('#submitButton').attr('disabled', 'disabled'); } }); 

The submit button remains disabled.

HTML:

 <form enctype="application/x-www-form-urlencoded" method="post" action="/controller/action"><dl class="zend_form"> <dd id="confirm-element"> <input type="hidden" name="confirm" value="0"><input type="checkbox" name="confirm" id="confirm" value="1" class="input-checkbox"></dd> <dt id="confirm-label"><label for="confirm" class="required">Lorem ipsum.</label></dt> <dt id="submitButton-label">&#160;</dt><dd id="submitButton-element"> <input type="submit" name="submitButton" id="submitButton" value="Potvrdiť" class="input-submit" disabled="disabled"></dd> <input type="hidden" name="csrf_token" value="ed3e9347145a3eb3d58c4c21d813df26" id=""></dl></form> 
+4
source share
3 answers

to try

 $('#confirm').change(function() { $('#submitButton').attr('disabled', !this.checked); }); 

according to the comments below, now this should fix your problem.

 $('#confirm').change(function() { $('#submitButton').button( "option", "disabled", !this.checked ); }); 
+1
source
 $("#submitButton").attr("disabled", true); 
0
source

You can disable this button, but you can still click on the button so that you unbind the click event from the button

 $("#submitButton").attr('disabled', 'disabled').unbind('click'); 
0
source

Source: https://habr.com/ru/post/1335367/


All Articles