Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Check all boxes :: JS howto?


DrDoc - 7:42 am on Aug 20, 2002 (gmt 0)


Thought #2:

document.forms[0] is an array as well, comtaining all the elements in the form. What you could do is something like this:

<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
function selectAll(){
t=document.forms[0].length;
for(i=1; i<t; i++) document.forms[0][i].checked=document.forms[0][0].checked;
}
</script>
</head>
<body>
<form method="post" action="script.php">
<input type="checkbox" name="test[]" value="select_all" onclick="selectAll();" />
<input type="checkbox" name="test[a]" value="1" />Choose 1
<input type="checkbox" name="test[b]" value="2" />Choose 2
<input type="checkbox" name="test[c]" value="3" />Choose 3
</form>
</body>
</html>

Now, say that you have a submit button or anything else after the checkboxes .. Well, simply don't try to check the last object then.

function selectAll(){
t=document.forms[0].length;
for(i=1; i<t
-1; i++) document.forms[0][i].checked=document.forms[0][0].checked;
}


Thread source:: http://www.webmasterworld.com/javascript/174.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com