Re: automatically selecting HTML drop down
| From: | David Newcomb | Date: | Mon, 14 Aug 2000 12:40:10 +0000 |
| Subject: | Re: automatically selecting HTML drop down | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11587@lists.php.net to get a copy of this message | ||
Alternativitly to save an "if" for every entry:
Put the the $currentStat one at the top which makes it
selected.
echo '<select name="state">';
echo '<option value="' . $currentState . '"';
for( $i = 0; $i < count($arr); $i++ )
{
echo "<option value='" . $arr[$i] . "'>\n";
}
echo '</select>';
HTH,
David.
----- Original Message -----
From: Matt McClanahan <cardinal@dodds.net>
To: Dustin Leggans <dustinl@rocketmail.com>
Cc: <php-general@lists.php.net>
Sent: Monday, August 14, 2000 7:32 AM
Subject: Re: [PHP] automatically selecting HTML drop down
> On Mon, 14 Aug 2000, Dustin Leggans wrote:
>
> > Hello..
> >
> > I am creating a phone book database... I have an "edit" page where users
can
> > come in and change their information, certain fields, like STATE, have
> > concrete values that will not vary from user to user therefore I use a
drop
> > down list. When this edit page comes up, I would like the STATE dropdown
to
> > default to the STATE value that the user has. For example, if a user
from
> > California logs in to change some information, the drop-down state list
> > should default to the CA value.
>
> Well, in order to fill in the other (text) fields, you'll need to query
> the DB in order to populate your edit form. It follows that you'd also
> have the state that they selected. So...
>
> // $currentState is the state they've picked previously
>
> $states = Array('Alabama','Alaska', ... 'Wyoming');
> echo '<select name="state">';
>
> for( $i = 0; $i < 51; $i++ )
> {
> echo '<option value="' . $arr[$i] . '"';
> if( $arr[$i] == $currentState )
> echo ' selected';
> echo '>' . "\n";
> }
>
> echo '</select>';
>
> HTH,
> Matt
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>