Enable Disable Submit Button If One Checkbox is Checked


Demo Download

When working with web forms, there are various situations where you need to enable or disable submit button, today I am going to share how to enable or disable submit button if at least one checkbox is checked using jQuery.

Following is the simple HTML form having checkboxes and submit button.

HTML

<form method="post" action="">
<input class="checks" type="checkbox" name="football" value="football" />
Football<br/>
<input class="checks" type="checkbox" name="cricket" value="cricket" />
Cricket<br/>
<input class="checks" type="checkbox" name="hockey" value="hockey" />
Hockey<br/><br/>
<input type="submit" id="submit" value="Submit" />
</form>

jQuery

$('#submit').prop("disabled", true);
$('input:checkbox').click(function() {
 if ($(this).is(':checked')) {
 $('#submit').prop("disabled", false);
 } else {
 if ($('.checks').filter(':checked').length < 1){
 $('#submit').attr('disabled',true);}
 }
});

In the above jQuery script you can see that submit button is disabled by default. However submit button will be enable it at least one checkbox is checked.

Don’t forget to add jQuery library before the above script.

Demo Download

If you found this tutorial helpful, kindly share it with your friends and developer groups.

Facebook Official Page: All PHP Tricks

Twitter Official Page: All PHP Tricks

Article By
Javed Ur Rehman is a passionate blogger and web developer, he loves to share web development tutorials and blogging tips. He usually writes about HTML, CSS, JavaScript, Jquery, Ajax, PHP and MySQL.
  1. Sir,,I need the answer for the same question in java eclipse .
    That how can enable the submit button if one checkbox is selected

    1. You will need some parameters, such as after successful payment, PayPal must return either payment is successful or failed parameter, if you received the successful parameter then you can make the button active.

  2. Good Day sir, i am making my project which is inventory system on PHP. Is it possible sir to access myModal from second page to first page? thank you sir if you can notice me . God Bless

Leave a Reply

Your email address will not be published. Required fields are marked *