
To set all checkboxes to true using JavaScript?

We can use following code to set all the checkboxes to true using javaScript.
Gyan

We can use following code to set all the checkboxes to true using javaScript.
Gyan

<head>
<script type="text/javascript">
function SelectAll() {
var checkboxes = document.getElementsByTagName("input");
for(i=0;i<checkboxes.length;i++) {
if(checkboxes.item(i).attributes["type"].value == "checkbox") {
checkboxes.item(i).checked = true;
}
}
}
function deSelectAll() {
var checkboxes = document.getElementsByTagName("input");
for(i=0;i<checkboxes.length;i++) {
if(checkboxes.item(i).attributes["type"].value == "checkbox") {
checkboxes.item(i).checked = false;
}
}
}
</script>
</head>
<body>
<input type="checkbox" name="list" value="1">Gyan<br>
<input type="checkbox" name="list" value="2">Singh<br>
<input type="checkbox" name="list" value="3">Ankit<br>
<input type="checkbox" name="list" value="4">Kumar<br>
<input type="checkbox" name="list" value="5">Kaushal<br>
<input type="submit" value="checkAll" onclick="SelectAll()" />
<input type="submit" value="uncheckAll" onclick="deSelectAll()" />
</body>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.