JQUERY allows us to find and manipulate HTML elements with very little coding. This tip is only a small example of that. The code below demonstrates how to retrieve all values of check boxes. Please remember to include reference to JQUERY before proceeding further.
function ShowAllValues() { var values = ""; $('input[type=checkbox]').each(function() { var value = $(this).parent().children("label").text(); if (this.checked == true) { values += value + ' : 1,\n'; } else { values += value + ' : 0,\n'; } }); alert(values); return false; }
Here the selector gets all the HTML input elements where the TYPE is ‘checkbox’
and the value is the label’s text that can be retrieved through the checkbox parent element.