Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Option field - Start at top

Posted on 2003-03-06
7
Medium Priority
?
188 Views
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?
0
Comment
Question by:palare98
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

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

Author Comment

by:palare98
ID: 8083788
I don't understand.
0
 
LVL 15

Expert Comment

by:VGR
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 :

<SELECT NAME=state>
<OPTION NAME="Alabama">Alabama</OPTION>
<OPTION NAME="South Dakota" SELECTED>South Dakota</OPTION>
</SELECT>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:palare98
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.
0
 
LVL 15

Accepted Solution

by:
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>";
$i=0;
while ($res=mysql_fetch_array(blahblahblah)) {
  // read $statename from $res["statename"] for example
  $i++;
  echo "<OPTION NAME=\"$statename\" ".(($i==1)?'SELECTED':'').">$statename</OPTION>";
} // while
echo "</SELECT>";
0
 

Author Comment

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

Author Comment

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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
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

564 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