Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery how to filter unchecked checkboxes from a form

Tags:

jquery

filter

In my page, i do have no.of checkboxes in the form. in that i am making checked some of them, i need to filter rest of the checkboxes and need to add separet event on those. i do like this:

var userLocales =   $('input[type="checkbox"]', "form").filter(function(){ 
                return $(this).val() === value["name"]
            }).prop("checked",true);

            $(userLocales).click(function(){
                $(this).parent().toggleClass("red");
            })

            $('input:checkbox:not("checked")', "form").not(userLocales).click(function(){
                $(this).parent().addClass("green"); //this is not working.. it works even for not selected elements..
            })

But not working.. any correct way to get this done pelase..?

like image 328
3gwebtrain Avatar asked Jun 27 '13 05:06

3gwebtrain


People also ask

How do I check uncheck all checkboxes with a button using jQuery?

Answer: Use the jQuery prop() method You can use the jQuery prop() method to check or uncheck a checkbox dynamically such as on click of button or an hyperlink etc. The prop() method require jQuery 1.6 and above.

How check if checkbox is unchecked?

prop() and is() method are the two way by which we can check whether a checkbox is checked in jQuery or not.

How do I uncheck a specific checkbox in jQuery?

By using jQuery function prop() you can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the checkbox unchecked.

How do I deselect a checkbox?

Clicking on the master checkbox selects all checkboxes; and unchecking it, deselects all checkboxes.


2 Answers

Given that you know how to get the checkboxes in the first place, consider:

checkboxes$.filter(':checked')....

or:

checkboxes$.filter(':not(:checked)')....
like image 77
Rob Von Nesselrode Avatar answered Nov 14 '22 20:11

Rob Von Nesselrode


You need to use :checked in the selector.

Try:

$('input:checkbox:not(":checked")', "form")

instead of

$('input:checkbox:not("checked")', "form")
like image 29
PSL Avatar answered Nov 14 '22 22:11

PSL