You could use my Values plugin (
http://plugins.jquery.com/project/values ) and do:
$(document).ready(function() {
$("input[name^=day]").change(function () {
var all = $('input[name^=day]').values();
for (var day in all) {
if (all[day] !== null) {
alert(all[day]+' was checked');
}
}
});
});
rather than just the value of the first matched one, this will give
you all of their current values in a key-value object.
On Wed, Aug 19, 2009 at 2:20 PM, blcArmadillo<[email protected]> wrote:
>
> I have a simple set of checkboxes:
>
> <input name="day1" type="checkbox" value="sun" /> Sun <input
> name="day2" type="checkbox" value="mon" /> Mon <input name="day3"
> type="checkbox" value="tue" /> Tue <input name="day4" type="checkbox"
> value="wed" /> Wed <input name="day5" type="checkbox" value="thu" />
> Thu <input name="day6" type="checkbox" value="fri" /> Fri <input
> name="day7" type="checkbox" value="sat" /> Sat
>
> When the state of one of them changes I want to check the state of all
> of them. So far I have:
> $(document).ready(function() {
> $("input[name^='day']").change(function () {
>
> });
> });
>
> My question is how do I get the value of each of the check boxes? It
> seems like all the commands I see in the jQuery documentation only
> give you the value of the first matched element? Do I have to use some
> sort of for loop? Thanks for the help.
>