Re: Defaults in drop down list...

From: Date: Mon, 06 Jan 2003 23:43:10 +0000
Subject: Re: Defaults in drop down list...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-130514@lists.php.net to get a copy of this message
At 11:54 AM 1/6/03 -0600, Steven Kallstrom wrote:
<select name="state">
            <option value="AL"{$stateselected['AL']}>Alabama</option>
            <option value="AK"{$stateselected['AK']}>Alaska</option>
            <option value="AZ"{$stateselected['AZ']}>Arizona</option>
            .
</select> $stateselected['$state'] is an array that stores the state that was selected on the prior form. is there an easier way, to have a default state picked out of this drop down list.???
Write a function that paints selects: $States = array( 'AL' => 'Alabama', ... function PaintSelect( $Name, $Values, $Selected ) { echo "<SELECT NAME=\"$Name\">\n"; reset( $Values ); while( list( $Index, $Value ) = each( $Values )) { $Selected = ( $Selected == $Index ) ? ' SELECTED' : ''; echo " <OPTION VALUE=\"$Index\"$SELECTED>$Value</OPTION>\n' } echo "</SELECT>\n"; } Then call lt like this ... State: <? PaintSelect( 'State', $States, $stateselected['$state'] ) ?><BR> Rick

« previous php.general (#130514) next »