Jump to content

[SOLVED] Multiple checkbox


bootes

Recommended Posts

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" 

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.