Re: making selection in drop down

From: Date: Fri, 28 May 2004 15:12:22 +0000
Subject: Re: making selection in drop down
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-187126@lists.php.net to get a copy of this message
"Alex Hogan" <Alex.Hogan@alliedelec.com> wrote in message news:0365FD6AC7A9014DAE77BDB3DCD0637D3CB73C@webmail.alliedelec.com... > > > Use HTML attribute "selected" in the option field you want to > > set as default... > > Yes.., thank you.., however I am more interested in how to force that selection to a specific option tag in the dropdown from a search. If I'm missing your point please excuse me. I'm a little brain dead this morning. > > If I have something like this what I'll want to do is to identify the point in the array where I can force the selected to be the default based on the previous search. > > <select name="sellocation" class="body_text" > id="sellocation"> > <option value="0" <?=$option[0]?>>Make Selection</option> > <? > $i = 1; > while($row = mssql_fetch_array($result)) > { > $v = $row['loc_id']; > $n = $row['loc_city']; > echo "<option value=\"$v\" $option[$i]>$n</option>"; > } Try this: while ($row = mssql_fetch_array($result)) { $v = $row['loc_id']; $n = $row['loc_city']; echo "<option value=\"$v\" "; // if current loc_id is previously selected loc_id set selected echo ($_POST['sellocation'] == $v) ? 'selected' : ''; echo "$option[$i]>$n</option>"; } Regards, Torsten Roehr

« previous php.general (#187126) next »