How to Checked single or all checkbox in javascript?

onClick Checkbox check all checkbox Using Javascript

File name : index.php

<!DOCTYPE html>
<html>
<body>
<head>
<title>Onclick Checkbox check all checkbox in Javascript</title>
</head>
<input type="checkbox" onClick="toggle(this)" /> Select All<br/>
<input type="checkbox" name="check" value="check1"> check 1<br/>
<input type="checkbox" name="check" value="check2"> check 2<br/>
<input type="checkbox" name="check" value="check3"> check 3<br/>
<input type="checkbox" name="check" value="check4"> check 4<br/>
<script>
function toggle(source) {
checkboxes = document.getElementsByName('check');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
</body>
</html>

Output :-

Onclick Checkbox check all checkbox in Javascript Select All
check 1
check 2
check 3
check 4





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here