0

I check other answer for similar problem, so either with this question:

Need select all Input:Checkbox from a Form but identifying his ID.

I try with: $( "input:checkbox[id^='ingr_']" ) and run perfect for "Checked" elements. So the unchecked elements, jquery said to use :not(:checked). Put this on the code then obtain nothing (checked or unchecked).

This is my sample code running on fiddle: JsFiddle

1
  • How about this $( "input[id^='ingr_']:checkbox") Commented Apr 1, 2015 at 22:57

2 Answers 2

1

I think the problem come from serializeArray() method. It removes unchecked checkbox.

https://api.jquery.com/serializeArray/

If you made ​​a console.log of $ ('input:checkbox[id^='comp_']:not(:checked)') , it works well.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, efectively serialize remove unchecked fields. How to emulate serializeArray to use this selection?
The solution was simply eliminate serializeArray because next line construct the string with selector
0

This code will count all unchecked checkboxes:

var countUnChecked = function() {
    var n = $('input:checkbox:not(":checked")').length
    alert( n + " Unchecked." );
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.