Jquery - check if at least one checkbox is checked andrey понедельник, 26 мая 2014 г. No Comment

     In some situation we need at least one user input in check box to submit form. In that case, we should check if at least one check box is checked. So, we can simply check that condition in .click event listener of check box.

     Here we are going to enable Submit Form button at least any one of check box is checked.

$("input[type='checkbox']").click(function () {
$("input[type='submit']").attr(
"disabled", !$("input[type='checkbox']").is(":checked"));
});
     From the above code  !$("input[type='checkbox']").is(":checked") will return switched value of boolean out put. 
i.e.,
If $("input[type='checkbox']").is(":checked") return true, output will be false.
If $("input[type='checkbox']").is(":checked") return false, output will be true.

     Because, if any one of the check box is checked, It will return true. So, we need change button's disabled attribute to false. For that we are using ! to change true to false and false to true .

Here is the DEMO.

Have any doubt, feel free to comment here!
     In some situation we need at least one user input in check box to submit form. In that case, we should check if at least one check box is checked. So, we can simply check that condition in .click event listener of check box.

     Here we are going to enable Submit Form button at least any one of check box is checked.

$("input[type='checkbox']").click(function () {
$("input[type='submit']").attr(
"disabled", !$("input[type='checkbox']").is(":checked"));
});
     From the above code  !$("input[type='checkbox']").is(":checked") will return switched value of boolean out put. 
i.e.,
If $("input[type='checkbox']").is(":checked") return true, output will be false.
If $("input[type='checkbox']").is(":checked") return false, output will be true.

     Because, if any one of the check box is checked, It will return true. So, we need change button's disabled attribute to false. For that we are using ! to change true to false and false to true .

Here is the DEMO.

Have any doubt, feel free to comment here!
by Jillur Rahman

Jillur Rahman is a Web designers. He enjoys to make blogger templates. He always try to make modern and 3D looking Templates. You can by his templates from Themeforest.

Follow him @ Twitter | Facebook | Google Plus

No Comment