I'm assuming you want the current value of the checked checboxes. Just
use .serialize()
var inputs = $("input[name^='day']").change(function () {
console.log(inputs.serialize());
});
the output of serialize() is a query string, just split on '&' for an
array of key=value that you can then process further as desired:
var inputs = $("input[name^='day']").change(function () {
$.each(inputs.serialize().split('&'),function(i,d){
d = d.split('=');
d[0]; //the key. eg day2
d[1]; //the value eg mon
});
});
On Aug 20, 7:34 am, Nathan Bubna <[email protected]> wrote:
> 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.