Re: automatically selecting HTML drop down

From: Date: Mon, 14 Aug 2000 06:32:49 +0000
Subject: Re: automatically selecting HTML drop down
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-11566@lists.php.net to get a copy of this message
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

« previous php.general (#11566) next »