$(document).ready(function() { $('input[type = "checkbox"]').change(function() { //when checkbox checked var nvalues = $('input[type="checkbox"]:checked').map(function() { return this.value; }).get(); if (nvalues.length > 0) { var fin = nvalues.value; $('#here').html(fin); } else { $('#here').html("wtf"); } }); });
here i'am storing checked values array using map output empty.
see comments in code:
$(document).ready(function() { $(':checkbox').change(function() { // :checkbox pseudo-selector selects checkboxes var nvalues = []; // initialize empty array $(':checkbox:checked').each(function() { // checked checkboxes nvalues.push($(this).val()); // push current checkbox value in array }); if (nvalues.length > 0) { $('#here').html(nvalues.tostring()); // array string conversion } else { $('#here').html("wtf"); } }); });
Comments
Post a Comment