Re: Detecting which item too select in a select

From: Date: Wed, 20 Dec 2000 04:02:00 +0000
Subject: Re: Detecting which item too select in a select
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31142@lists.php.net to get a copy of this message
<SELECT NAME="select"> <? $array = array( 1 => 'foo', 2 => 'test', 3 => 'what up?'); while(list($key,$val) = each($array)) { echo '<OPTION VALUE="'.$key.'" '; if($select == $key) { echo ' SELECTED '; } echo '>'.$val.'</OPTION>'."\n"; } ?> </SELECT> --Joe On Wed, Dec 20, 2000 at 01:31:45PM +1030, Joseph H Blythe wrote: > hey all, > > I asked this question some time ago, but could not figure this one out. > > basically I need some way of detecting which item is selected in a form's drop down list > this is the way I have been doing it in the past: > > <select name="foo"> > <?php if ( $somevar == 1 ) { ?> > <option value="1" selected>1</option> > <?php } else { ?> > <option value="1">1</option> > <?php } if ( $somevar == 2 ) { ?> > <option value="2" selected>2</option> > <?php } else { ?> > <option value="2">2</option> > <?php } if ( $somevar == 3 ) { ?> > <option value="3" selected>3</option> > <?php } else { ?> > <option value="3">3</option> > <?php } ?> > </select> > > you can imagine how cluncky this gets when using a large list like country codes etc.. and > seeing im using FastTemplates I do not want to use this method. > > Any ideas would be appreciated, > > Regards > > Joseph > > -- > 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 --- Joe Stump PHP Programmer www.Care2.com

« previous php.general (#31142) next »