Re: making selection in drop down

From: Date: Fri, 28 May 2004 15:11:48 +0000
Subject: Re: making selection in drop down
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-187127@lists.php.net to get a copy of this message
I use a javascript to help me with bigger dropdowns... <script> function get_links() { document.all["field_name"].value='<?echo"$field_name"; ?>' </script> "Torsten Roehr" <roehr@zilleon.com> 28/05/2004 16:12 To php-general@lists.php.net cc Subject Re: [PHP] making selection in drop down "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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ********************************************************************* The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. ***********************************************************************

« previous php.general (#187127) next »