Re: selected = true

From: Date: Mon, 22 Jan 2001 22:31:19 +0000
Subject: Re: selected = true
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36106@lists.php.net to get a copy of this message
> Hey all. Does anyone have any ideas how I can carry over a selected value? > :) It's probably easy but my mind is making it difficult. A value is > stored for a record in the DB which had been previously assigned through a #get all the possible options into an array $options $options = array('red', 'yellow', 'green'); #get the selected option into a variable $option $option = 'yellow'; echo "<SELECT>\n"; while (list(,$opt) = each($options)){ $selected = ($opt == $option) ? 'SELECTED' : ''; echo "<OPTION $opt $selected>$opt</OPTION>\n"; } echo "</SELECT>\n"; Twist on a theme: If you can have a pre-determined order, you can have this work with multiple selections, but only advancing the selected array (or result set or whatever) when you have a match. Don't miss the Zend Web Store's Grand Opening on January 23, 2001! http://www.zend.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#36106) next »