rashmi_k28 Posted October 14, 2008 Share Posted October 14, 2008 <SCRIPT LANGUAGE="JavaScript"> function CheckAll(chk) { for (i = 0; i < chk.length; i++) chk[i].checked = true ; } function UnCheckAll(chk) { for (i = 0; i < chk.length; i++) chk[i].checked = false ; } </script> <input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.myform.check_list)"> <input type="button" name="Un_CheckAll" value="Uncheck All" onClick="UnCheckAll(document.myform.check_list)"> <input type="checkbox" name="check_list[]" value="1">1 <input type="checkbox" name="check_list[]" value="2">2 <input type="checkbox" name="check_list[]" value="3">3 When I click on the CheckAll button, it doesnot check all the boxes. If I use <input type="checkbox" name="check_list" value="1">1 <input type="checkbox" name="check_list" value="2">2 <input type="checkbox" name="check_list" value="3">3 This works. How can I pass the multiple value in the array to another page Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 15, 2008 Share Posted October 15, 2008 It would be nice to see more of the code - especially how you are calling the function. Are you using 'checl_list' or 'check_list[]'? Because you have defined the names as array names, you can't referenence them in all the same ways. For example you CAN't use this: document.forms[0].check_list[] But you CAN use this document.forms[0]['check_list[]'] You only need ONE function, just pass a bool value for the check state. Here's a revise function and a way to properly reference the check objects <html> <head> <script type="text/javascript"> function CheckAll(chkObj, chkBool) { for (i = 0; i < chkObj.length; i++) { chkObj[i].checked = chkBool; } } </script> </head> <body> <form> <input type="checkbox" name="check_list[]" value="1">1<br /> <input type="checkbox" name="check_list[]" value="2">2<br /> <input type="checkbox" name="check_list[]" value="3">3<br /> <br /><br /> <button onclick="CheckAll(document.forms[0]['check_list[]'], true)">Check All</button> <button onclick="CheckAll(document.forms[0]['check_list[]'], false)">Check None</button> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
xtopolis Posted October 15, 2008 Share Posted October 15, 2008 nice one mj, i was wondering how to solve this as well. It submits the form for me on click of a button, so OP if it does for you, add the word return to the function call, and return false after the for loop in the function itself. 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.