Jump to content

How do you collect string data into combo boxes(form)! [SOLVED]


ted_chou12

Recommended Posts

Sorry for posting lots of new topics, but i really need helps with these.
So far, ive learnt how to input information information easily into textarea and input boxes, eg. <?php echo"$string"?>, however im having trouble inputing the to the combo boxes, (ie. the selection types)
is there any easy way to do that?
Thanks :D
Link to comment
Share on other sites

Edited: nope, i think you got the wrong picture here, what i wish to do is having the combo box selecting the value that I previously submitted, not collecting the value selected, if you still dont understand my point i will explain it in further details
thanks for understanding.

i dont quite understand, could you explain please?
eg.
[code]
<tr><td valign=top><font face="Arial">Background Color:</font></td>
<td><select name="bgcolor" size="1">
<option value="FFFFFF">White</option><option value="87CEFA">Light sky blue</option><option value="FFA500">Orange</option><option value="8B4513">Saddle brown </option><option value="C0C0C0">Silver</option><option value="FA8072">Salmon</option><option value="CD853F">Peru</option><option value="D2B48C">Tan</option><option value="FF69B4">Hot pink</option></select></td></tr>
[/code]

these are my multiple choices, where would i have to put the $_GET['bgcolor']?
thanks a lot by the way
Link to comment
Share on other sites

The easiest way I've found:

[code]$colors = array(
'FFFFFF' => 'White',
'87CEFA' => 'Light sky blue',
'FFA500' => 'Orange',
'8B4513' => 'Saddle brown ',
'C0C0C0' => 'Silver',
'FA8072' => 'Salmon',
'CD853F' => 'Peru',
'D2B48C' => 'Tan',
'FF69B4' => 'Hot pink'
);

$color_select = "";

foreach ($colors as $hex => $color) {
$color_select .= '
<option value="' . $hex . '"';

if ($hex == $_POST['bgcolor']) {
$color_select .= ' selected';
}

$color_select .= '>' . $color . '</option>';
}

?>
<tr>
<td valign=top><font face="Arial">Background Color:</font></td>
<td>
<select name="bgcolor" size="1">
<?php echo $color_select; ?>
</select>
</td>
</tr>[/code]
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.