bootes Posted October 21, 2009 Share Posted October 21, 2009 I have set up various radio/checkboxes with single entities, and am able to, once the radio/checkbox has been selected to store/retrieve and display. But I can't figure out how to refresh multiple checkbox selections. My problem is that the displayed value is large, and I just want to store the key value of the array, then use that corresponding value to enable the checkbox upon loading the record. Make sense? Seems like it should be simple enough, or perhaps there is a better way to do this? Thank you, Bob <b><input type="checkbox" name="aorgs[]" value="1" />.....</b><br /> <b><input type="checkbox" name="aorgs[]" value="2" <b><input type="checkbox" name="aorgs[]" value="3" <b><input type="checkbox" name="aorgs[]" value="4" <b><input type="checkbox" name="aorgs[]" value="5" <b><input type="checkbox" name="aorgs[]" value="6" <b><input type="checkbox" name="aorgs[]" value="7" Quote Link to comment https://forums.phpfreaks.com/topic/178424-solved-multiple-checkbox/ Share on other sites More sharing options...
Psycho Posted October 21, 2009 Share Posted October 21, 2009 Well, you don't show the format of the saved values or anything to really go on. But, I would generate two arrays: 1) The array of all possible values for the checkboxes and 2) an array fo the saved values (if any). Then create a procedure for displaying the checkboxes and checking any as needed: $values = array ('1', '2', '3', '4', '5', '6', '7'); $selected = array('1', '4', '5'); foreach ($values as $value) { $checed = (in_array($value, $selected)) ? ' checked="checked"': '' ; echo "<input type=\"checkbox\" name=\"aorgs[]\" value=\"{$value}\"{$checked}>{$value}<br />\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/178424-solved-multiple-checkbox/#findComment-940920 Share on other sites More sharing options...
bootes Posted October 21, 2009 Author Share Posted October 21, 2009 Thank you...that'll do the trick. The checked='checked' is what I was looking for...I already use this in a multiple radio form (selected='selected') but just couldn't see the forest for the trees. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/178424-solved-multiple-checkbox/#findComment-941152 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.