TheConeHead
Programmer
I have a set of checkboxes all named the same - how can I make a link "Select all" to have them all checked?
![[conehead] [conehead] [conehead]](/data/assets/smilies/conehead.gif)
![[conehead] [conehead] [conehead]](/data/assets/smilies/conehead.gif)
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
var cboxes = document.getElementsByName('checkboxname');
for (var ci=0;ci<cboxes.length;ci++)
{
cboxes[ci].checked = true;
}
[code]
Lee
<script type="text/javascript">
function checkAll() {
var checkBoxes = document.forms["blahForm"].elements["chk"];
for (i = 0; i < checkBoxes.length; i++) {
document.forms["blahForm"].elements["chk"][i].checked = true;
}
}
</script>
<a href="#" onclick="checkAll();return false;">Check All</a><br>
<form name="blahForm">
<input type="checkbox" name="chk" />
<input type="checkbox" name="chk" />
<input type="checkbox" name="chk" />
<input type="checkbox" name="chk" />
<input type="checkbox" name="chk" />
<input type="checkbox" name="chk" />
<input type="checkbox" name="chk" />
<input type="checkbox" name="chk" />
</form>