Get dynamic checkbox values with jQuery
checkbox, javascript, jquery
Solution
You had an `Uncaught ReferenceError: i is not defined`; I've updated your fiddle here:
http://jsfiddle.net/hxfsB/24/
$('#envoyer').click(function(e){
var myArray = new Array(3);
for ( var j = 0; j < 3; j++) {
var check=$('input:checkbox[name=checkbox'+j+']').is(':checked');
if(check==true)
myArray[j]=$('input:checkbox[name=checkbox'+j+']').val();
// Alert Current Selection //
alert('check ' + " " + myArray[j] );
}
});
Keep in mind: `undefined` means the checkbox is NOT selected.
I hope this helps!
Problem
I can't get the checked values of the dynamic check box. What am I doing wrong? http://jsfiddle.net/hxfsB/17/ Markup: ``` <html> <body> one<input type="checkbox" name='checkbox0' value="one_name" checked> two<input type="checkbox" name='checkbox1' value="one_name1"> three<input type="checkbox" name='checkbox2' value="one_name2"> <input type="button" id="envoyer" value="Envoyer Reponse" /> </body> </html> ``` Javascript: ``` $('#envoyer').click(function(e){ var myArray=new Array(4); for ( var j = 0; j < 3; j++){ var check=$('input:checkbox[name=checkbox'+j+']').is(':checked'); if(check==true) myArray[j]=$('input:checkbox[name=checkbox'+j+']').val(); } alert('check '+" "+myArray[i]); }); ```