Option field - Start at top

Posted on 2003-03-06
Medium Priority
Last Modified: 2008-03-06
I have a form that has 3 option fields.

They seem to be defaulting to the center of the list (probably the last record that I entered's value).  I need this to always start at the top.  For instance, if I was using the USA for a state list, it might start in South Dakota, not Alabama.  Thoughts?
Question by:palare98
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 15

Expert Comment

ID: 8083458
provide the desired OPTION with a well-placed SELECTED attribute ;-)

Author Comment

ID: 8083788
I don't understand.
LVL 15

Expert Comment

ID: 8084250
unless I did misunderstand you,
you want that one of the OPTIONs is selected in stead of the last one inserted (or the first one in alphabetical order, IMHO)

Then your SELECT should look like this :

<OPTION NAME="Alabama">Alabama</OPTION>
<OPTION NAME="South Dakota" SELECTED>South Dakota</OPTION>
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8084464
Did I leave out the part that this is being dynamically generated from a seperate table?  I'm sorry.  Does it work the same way?  Or is there a way to always start at the beginning, regardless of what the beginning is?  If this drastically changes the question, I'll up the points.
LVL 15

Accepted Solution

VGR earned 200 total points
ID: 8084591
no, it doesn't change anything. Of course that I suspected you had a query running somewhere to generate the states' names (for example) : nobody would be fool enough to enter them by hand :D :D

If you want do have always the first element selected by default, then simply do this in your while loop (if a for loop, it's even simplier)

echo "<SELECT>";
while ($res=mysql_fetch_array(blahblahblah)) {
  // read $statename from $res["statename"] for example
  echo "<OPTION NAME=\"$statename\" ".(($i==1)?'SELECTED':'').">$statename</OPTION>";
} // while
echo "</SELECT>";

Author Comment

ID: 8084629
I can't test this until the morning...Thanks...I'll let you know how it turns out.

Author Comment

ID: 8103796
I don't have time to test this...I'm sorry.  I'm sure that its righteous.  Thanks for he answer.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question