KitCarl Posted May 3, 2010 Share Posted May 3, 2010 I have a check box group and would like to include a All check box, but do not now how to code the value to have the multiple values in one check box passed into the array? <label> <strong> <input type="checkbox" name="association[]" value="1" checked id="association_4" /> IBGA</strong></label> <strong> <label> <input type="checkbox" name="association[]" value="3" id="association_5" /> PBGA</label> <label> <input type="checkbox" name="association[]" value="2" id="association_6" /> NEHBA</label> Here is the PHP code(My thanks to Cags for the implode statement). I would like to set the Else to be the All check box value. IF (!empty($_POST['association'])) $association = $association = "'" . implode("','", $_POST['association']) . "'"; ELSE $association = "'1'"; Presently the check boxes names and values are hand coded, but they match names & values in a database table. I'd like to see the quick fix to learn how it is done, but assume the better way long term to handle it is by pulling the Names & Values from the database. While that is above my knowledge level, I wouldn't mind seeing how that is done to try to understand that method as well. Quote Link to comment Share on other sites More sharing options...
Zane Posted May 3, 2010 Share Posted May 3, 2010 something like that function checkUncheckAll() { for(var i=0; i if(inputs[i].type == 'checkbox') { // check the box or uncheck it. inputs[i].checked = inputs[i].checked ? false : true; } } } Quote Link to comment Share on other sites More sharing options...
satya61229 Posted May 3, 2010 Share Posted May 3, 2010 Are you looking for this article? I think so! Check, Uncheck All Checkboxes Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 3, 2010 Share Posted May 3, 2010 Building upon Zanus's code, here is an example using your form elements (with some corrections to the HTML) <html> <head> <style> label { font-weight: bold; } </style> <script type="text/javascript"> function checkUncheckAll(groupName, checkState) { var groupObj = document.forms[0].elements[groupName]; var groupLen = groupObj.length; for(var groupIdx=0; groupIdx<groupLen; groupIdx++) { groupObj[groupIdx].checked = checkState; } return; } </script> </head> <body> <form name="test"> <input type="checkbox" name="association[]" value="1" checked id="association_4" /> <label for="association_4">IBGA</label> <input type="checkbox" name="association[]" value="3" id="association_5" /> <label for="association_5">PBGA</label> <input type="checkbox" name="association[]" value="2" id="association_6" /> <label for="association_6">NEHBA</label> <br /><br /> <input type="checkbox" name="checkAll" value="x" id="checkAll" onclick="checkUncheckAll('association[]', this.checked)" /> <label for="checkAll">Check All</label> </form> </body> </html> 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.