Re: Detecting which item too select in a select

From: Date: Wed, 20 Dec 2000 04:04:15 +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-31144@lists.php.net to get a copy of this message
On Wed, 20 Dec 2000, 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: Well, you could rework this fairly easilly with a for loop. <select name="foof"> <? for ($i = 1; $i < 4; $i++) { ?> <option value="<? echo $i ?>" <? echo ($i == $somevar) ? ' selected' : '' ?>><? echo $i ?> </option> <? } ?> Or something to that effect. For dropdowns with values that are strings, it'd be easier to do it in an array and a while loop, which I'm sure somebody will mention. Matt

« previous php.general (#31144) next »