Welcome Guest, Not a member yet? Register   Sign In
Set select to post-value else use given value
#4

[eluser]Grind[/eluser]
The user guide says this:
Code:
<select name="myselect">
<option value="one" &lt;?php echo set_select('myselect', 'one', TRUE); ?&gt; >One</option>
<option value="two" &lt;?php echo set_select('myselect', 'two'); ?&gt; >Two</option>
<option value="three" &lt;?php echo set_select('myselect', 'three'); ?&gt; >Three</option>
</select>

That would be fine, but in my case all the data is selected out of a database:

Code:
$options = array('one', 'two', 'three');
$default_value = 'one';

echo '<select name="myselect">';
foreach($options as $value)
{
   echo '<option value="'.$value.'" '.set_select('myselect', $value).'>'.$value.'</option>';
}
echo '</select>';

In this case, how can I select the option that's equal to $default_value if no form is submitted? If form submitted, the submitted option must be selected.
Hope this makes it a little bit clearer.


Messages In This Thread
Set select to post-value else use given value - by El Forum - 11-04-2009, 09:20 AM
Set select to post-value else use given value - by El Forum - 11-04-2009, 09:22 AM
Set select to post-value else use given value - by El Forum - 11-04-2009, 09:23 AM
Set select to post-value else use given value - by El Forum - 11-04-2009, 09:37 AM
Set select to post-value else use given value - by El Forum - 11-04-2009, 09:46 AM
Set select to post-value else use given value - by El Forum - 11-04-2009, 09:51 AM
Set select to post-value else use given value - by El Forum - 11-04-2009, 10:05 AM
Set select to post-value else use given value - by El Forum - 11-04-2009, 10:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB