Suppose I have a JSP page containing checkbox:
<input type="checkbox" name=check<%=i%> value=<%= rs.getString("VDB") %>>
Here value of i depends on number of value retrieved from database.
I need a button to check all checkboxes.
I know how to check all checkboxes if name of all checkboxes are same(For E.g: chk) using:
<SCRIPT LANGUAGE="JavaScript">
function Check(chk) {
if (document.vendorform.Check_All.value == "Check All") {
for (i = 0; i < chk.length; i++)
chk[i].checked = true;
document.vendorform.Check_All.value = "UnCheck All";
} else {
for (i = 0; i < chk.length; i++)
chk[i].checked = false;
document.vendorform.Check_All.value = "Check All";
}
}
</script>
Any help in JavaScript only as I am not aware of JSTL,jQuery OR EL.
For plain javascript have a look at the following link and see if that helps:
Check all Checkboxes
It suggests the following:
For jQuery you would simply need to use the
:checkbox selectormore information on that can be found here:jQuery Checkbox Selector