Thursday, 28 April 2016
How to use Select All checkboxes and getting values into array using JavaScript and jQuery
Here I will explain about Select and UnSelect all checkboxes using single Select All checkbox. To use this code you need jQuery plugin version 1.6 and above. If you want to get selected checkboxes values use the below code.
HTML:
<input type="checkbox" id="chkAll" />
<input type='checkbox' name='chkSelect' value=" + slno + " class='chkSelect'>
JavaScript:
$("#chkAll").change(function () {
$(".chkSelect").prop('checked', $(this).prop("checked"));
});
var arrayCatIds = [];//Declare array.
$('input:checkbox[name=chkSelect]:checked').each(function () {
arrayCatIds.push($(this).val());//Here pushing all selected checkboxes into array
});
HTML:
<input type="checkbox" id="chkAll" />
<input type='checkbox' name='chkSelect' value=" + slno + " class='chkSelect'>
JavaScript:
$("#chkAll").change(function () {
$(".chkSelect").prop('checked', $(this).prop("checked"));
});
var arrayCatIds = [];//Declare array.
$('input:checkbox[name=chkSelect]:checked').each(function () {
arrayCatIds.push($(this).val());//Here pushing all selected checkboxes into array
});
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment