dasein Posted February 28, 2009 Share Posted February 28, 2009 I have a function in the header which simply allows for all the checkboxes of the same name to be selected: function checkAll(field) { for (i = 0; i < field.length; i++) field.checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field.checked = false ; } But I can't use the [] brackets like this with that function. <form name="test" action="testform.php" method="post"> <input type='checkbox' name='member_type[]' value='FM'>Full Member<br> <input type='checkbox' name='member_type[]' value='JM'>Junior Member<br> <input type='checkbox' name='member_type[]' value='LM'>Lady Member<br> <input type='checkbox' name='member_type[]' value='MM'>Make Member<br> <input type='checkbox' name='member_type[]' value='OM'>Outside Member<br> <input type="submit" value="SUBMIT"> To run a php script to read the checkboxes as an array (there are actually about 50 with the same name), I have to have the [] brackets. $types = $_POST['member_type']; // array of values selected by the user foreach($types as $key=>$val){ $types_search.=$val.", "; } I want to have both, but they seem to not work together. Is there a minor workaround to this? I hope I explained this okay. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/147337-check-all-function-and-checkbox-array-conflict/ Share on other sites More sharing options...
dt192 Posted February 28, 2009 Share Posted February 28, 2009 you can get javascript functions that check boxes based on class rather than name so that would be the way to go, then you wont mess up the PHP Quote Link to comment https://forums.phpfreaks.com/topic/147337-check-all-function-and-checkbox-array-conflict/#findComment-773513 Share on other sites More sharing options...
dasein Posted March 1, 2009 Author Share Posted March 1, 2009 Thank you, dt192. I'm not quite sure I follow you though. You're saying I should place the checkboxes in a class in a CSS file for the HTML page? Quote Link to comment https://forums.phpfreaks.com/topic/147337-check-all-function-and-checkbox-array-conflict/#findComment-773561 Share on other sites More sharing options...
RussellReal Posted March 1, 2009 Share Posted March 1, 2009 you can utilize javascript's "node" functions for example if you added in an id for those forms lets say you id'd one 'test' you could do function checkAll(eid) { var children = document.getElementById(eid).childNodes; for (i = 0; i < children.length; i++) { children[i].checked = true; } } Quote Link to comment https://forums.phpfreaks.com/topic/147337-check-all-function-and-checkbox-array-conflict/#findComment-773575 Share on other sites More sharing options...
dasein Posted March 1, 2009 Author Share Posted March 1, 2009 Thanks, RusselReal. It still won't work both ways. Quote Link to comment https://forums.phpfreaks.com/topic/147337-check-all-function-and-checkbox-array-conflict/#findComment-773997 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.