|
Often, we run into situations where we would love to have just one button to select all the options on a given page. For example, in Webmail, if I want to delete old emails or junk emails, it is easier to select them all and then click delete. However, it is pain if I have to select each and every email one by one. One check box that can select and unselect all them at once comes to help.
At KSPTech, we ran into a similar situation with a project. Following is the javascript code snippete that I would like to share with you on as is basis.
checked = false;
function toggleCheckbox (list) {
if (checked == false) {
checked = true;
} else {
checked = false;
}
for (i = 0; i < list.length; i++) {
list[i].checked = checked;
}
}
.......
<form name="myform">
<input type="checkbox" name="list" >
<input type="checkbox" name="list" >
bunch of more check boxes to be toggled
</form>
<input type='checkbox' onclick='toggleCheckbox(document.myform.list)'> Select / Unselect All |