JazzyB Posted May 4, 2007 Share Posted May 4, 2007 Hi everyone, I have a form with checkboxes and I've assigned them names using numbers. The problem is it does not allow the following script to work: <script language=JavaScript> function checkAll(){ document.form.1.checked = true; document.form.2.checked = true; document.form.3.checked = true; } function unCheckAll(){ document.form.1.checked = false; document.form.2.checked = false; document.form.3.checked = false; } </script> Here's the form: <form name="form" id="form"> <table width="309" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F8F7F6"> <tr> <td width="122"><div align="right">Select All </div></td> <td width="20"> <input type="checkbox" name="checkbox" value="checkbox" onClick="if (this.checked){checkAll()} else if (!this.checked){unCheckAll()}" /></td> <td width="112"><div align="right">box1</div></td> <td width="25"> <input type=checkbox name=1 value=yes /> </td></tr> <tr> <td><div align="right">box2 </div></td> <td> <input type=checkbox name=2 value=yes /> </td> <td><div align="right">box3</div></td> <td><input type=checkbox name=3 value=yes /></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> <td> </td> </tr> </table> </form> The script works when the names of the checkbox contain letters. Is there any way that I can make it work with only numbers? Please help. Quote Link to comment Share on other sites More sharing options...
fenway Posted May 4, 2007 Share Posted May 4, 2007 Try document.forms['form'].elements[1'].checked, etc. Quote Link to comment Share on other sites More sharing options...
JazzyB Posted May 5, 2007 Author Share Posted May 5, 2007 Thank you, it's working fine now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.