"deko" <ww*******************************@nospam.com> wrote in
news:Sn***************@newssvr13.news.prodigy.com:
I populate a drop-down list like this:
echo "<select>";
foreach ( $ip_list as $var )
{
echo "<option>";
echo $var;
echo "</option>";
}
echo "</select>";
Is it possible to have the selection in the drop-down list default to
a particular value? For example, let's say the complete list of
values looks like this:
65.162.31.155
210.213.149.6
68.190.20.83
130.202.234.254
68.122.35.157
When the page is loaded, I want 68.190.20.83 to appear as the selected
value in the drop-down list. Can this be done? Any suggestions or
examples welcome!
Thanks!
There is probably a better way to do this since this was just a quick and
dirty method to make it work for me.....
HTML requires the particular menu choice to be listed as 'selected'. So
you can make an array of choices (listed by name instead of number) that
match the ones in the HTML, default them to nothing. and set the proper
one to 'selected'. In the HTML, add php code to each choice. The ones
that are blank will be ignored. The one with 'selected' will be the
choice.
the starting php
$select = array("none"=>"", "porche"=>"", "mustang"=>"", "corvette"=>"");
$select['porche'] = 'selected';
The normal HTML unselected option line looks like this
<option value="none">Porche</option>
The line that is selected via HTML is
<option value="none" selected>Porche</option>
The line using a php array is
<option value="none" <? print $select['porche']; ?> >None</option>
If porche was set as 'selected' when setting up the array, it will match
example #2. If not, it will match #1. You can expand on this by using
choices in a database instead of creating the array manually.
If there IS a better way I will also be interested ;o)