Well the variable is undefined because your selector is wrong Your selector $('input[name=foo]:
would find <input type="checkbox" name="foo" value="klaybul1" /> not "foo[]"...... different names, different results besides, i don't believe (could be mistaken) that selecting checkboxes and saying ".val()" won't result in an array of values but rather the value of the first selected object only this would work though var vals = []; $("input[name^='foo']").each(function() { if (this.checked) { vals.push(this.value); } }); //So now "vals" would be an array of selected values to send through a post, which won't easily recognize an array $.post( "page.php", { values: vals.join(",") }, function(data) { //do something with results } ); On Mar 2, 12:08 am, mklebel <mkle...@gmail.com> wrote: > Been losing my hair on this. > I'm trying to assign my checkbox array to a variable that I can send > through a post. But I the variable 'tempy' is always undefined. I must > be confused on how to reference an array, or maybe there is a better > way to do this? > > js: > var tempy = $('input[name=foo]:checked').val(); > > html: > <input type="checkbox" name="foo[]" value="klaybul1" /> > <input type="checkbox" name="foo[]" value="klaybul2" /> > <input type="checkbox" name="foo[]" value="klaybul3" /> > > Thanks in advance!