Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  83] [ 2]  / answers: 1 / hits: 31679  / 11 Years ago, fri, july 5, 2013, 12:00:00
<script type="text/javascript">
function checkAll(formname, checktoggle)
{
var checkboxes = new Array();
checkboxes = document[formname].getElementsByTagName('input');
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type === 'checkbox') {
checkboxes[i].checked = checktoggle;
}
}
}
</script>

<form name="myform">
<li>
<label class="cba">
<a href="javascript:void();" onclick="javascript:checkAll('myform', true);">Check All</a> |
<a href="javascript:void();" onclick="javascript:checkAll('myform', false);">UnCheck All</a>
</label>
</li>
<li>
<input class="cba" type="checkbox" name="content1" value="1"<?php checked('1', $slct); ?>/>
</li>
<li>
<input class="cbc" type="checkbox" name="content2" value="2"<?php checked('2', $copy); ?>/>
</li>
<li>
<input class="cbx" type="checkbox" name="content3" value="3"<?php checked('3', $cut); ?>/>
</li>
</form>

I have made the toggle option for the checkbox check all and uncheck all. Still now check all and uncheck all is not working I get the error in console while viewing in Firebug. Here is the screenshot I attached.
I am not sure what was my mistake:


enter


Any suggestion would be great.


More From » php

 Answers
5

Your syntax is incorrect. Your missing the .forms so it should look like this



document.forms[formName].getElementsByTagName(input);

[#77183] Wednesday, July 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarrodfletchers

Total Points: 75
Total Questions: 94
Total Answers: 95

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
;