jQuery : find empty select boxes (or selects with a specific value)
Another super short jQuery solution to a super long late-night quest on my part.
I have a form with a variable number of select boxes. Before the form can be submitted, I need to verify that there are no selections left unchanged.
The select boxes start out with a default value of '' (empty quotes). To search for them , i was using all sorts of variations on jquery 'val()', but that is more useful for setting a value than finding a select with a value. After a few various connotations... here's the one that works:
var valCt = $('select.colorselect[value=""]').size();
This finds all selects with the class of 'colorselect' and the value of '', and returns the size, which in jQuery talk means 'how many'. If I have 3 unchanged select boxes, valCt will equal '3'.
From there it is an easy hop to add a check to the submit action of my form, checking to make sure valCt is 0.
if (!(valCt == 0)) {
return false
} else [ ... submit form here ... ]


$("input.parent").click(function() { $("input:checkbox", $(this) ).attr("checked", $(this).checked ); });
I just love jQuery!!
one question on your example - what does the second part of the selector do, after the comma?
i.e. what does this line do:
$("input:checkbox", $(this) )
as opposed to simply:
$("input:checkbox")
?
I know I have seen that syntax before but didn't retain the meaning... too much to learn all the time!