squiggerz Posted September 7, 2007 Share Posted September 7, 2007 OK, I found this javascript code (below) that takes a "Check All" button and checks every checkbox in a group. My problem is where it does the onClick="checkAll(document.myform.list) <-- my 'list' is set up with input names like this 'list[]' because it posts the values checked into an array that I later combine to form a string. but the [] seems to prevent the javascript from working as when I drop the [] from my checkboxes, the javascript works (my post doesnt of course). I'm a complete moron when it comes to javascript and I know this is a php forum, but I'm just hoping somebody here has dealt with this in the past and knows the easy way around. <SCRIPT LANGUAGE="JavaScript"> // <input type=button name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> // <input type=button name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } </script> Quote Link to comment Share on other sites More sharing options...
poizn Posted September 7, 2007 Share Posted September 7, 2007 Hi I dont know if I understand your question fully, but ill give it a go. My first attempt... You could make you functions take two arguments. First argument would be the form you working on, and the second would be the list of checkboxes // <input type=button name="CheckAll" value="Check All" onClick="checkAll(document.myform , A LIST OF THE FIELDS)"> function checkAll(form , fields) { for(i = 0; i < fields.length; i++) form.fields[i].checked = true; } Second attempt Just pass all the id's to the function like so function checkAll(ids) { for(i = 0; i < ids.length; i++) document.getElementById(ids[i]).checked = true; } I hope this help Thanks Daniel 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.