I am trying to use this code on my site <SCRIPT LANGUAGE="JavaScript"> //Check all radio/check buttons script- by javascriptkit.com //Visit JavaScript Kit (http://javascriptkit.com) for script //Credit must stay intact for use function checkall(formname,checkname,thestate){ var el_collection=eval("document.forms."+formname+"."+checkname) for (c=0;c<el_collection.length;c++) el_collection[c].checked=thestate } </script> Code (markup): then on the html i have something like this <form name="test"> <input type="checkbox" name="siteid[]" value="2" checked="checked">site2<br> <input type="checkbox" name="siteid[]" value="3">site3<br> <input type="checkbox" name="siteid[]" value="4">site4</td><td> <!-- checkall(name of form, common name of checkbox group, true or false)--> <a href="javascript:checkall('test','siteid[]',true)">Check All</a><br> Code (markup): I also tryed this <a href="javascript:checkall('test','siteid',true)">Check All</a> Code (markup): none worked can anybody help me out? thx ins andvance BTW... if anybody has a solution of checking/unchecking using the same link that would be apreciated.
I don't like the example from JavaScript Kit you're using, but here's what you can do to fix it. function checkall(formname,checkname,thestate){ //var el_collection=eval("document.forms."+formname+"."+checkname) var el_collection=document.forms[formname].elements[checkname]; for (c=0;c<el_collection.length;c++) el_collection[c].checked=thestate } Code (markup): The main problem you were having with the code is the use of brackets in the checkbox name. PHP requires this, but javascript doesn't like it when you use the syntax document.forms.test.siteid[] so instead I changed it to reference the elements collection, which takes a string, so you can include the brackets. Also, I got rid of the eval, because that was only necessary when trying to append a string onto the "document.forms.test.siteid[]" syntax. I tested in IE and FF. Edit: To use the same script for checking and unchecking, you might want to use another checkbox that represents a check/uncheck all, instead of using a button. Then on that checkbox's onclick event, you call the same function, and also pass in the checked value.