Solved

<SELECT> with no default selection

Posted on 2003-11-12
9
666 Views
Last Modified: 2010-04-09
Hi,

I would like to populate a SELECT tag with options, but have no option selected until the user explicitly chooses one. The default behavior is that the first option is displayed in the select box, but I would like the selection to be blank until the user selects from the dropdown menu, as a visual que that he must do so. How can I do this?

Thanks very much,

Rich
0
Comment
Question by:RichardFox
  • 4
  • 3
  • 2
9 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 50 total points
ID: 9732358
<BODY onload="document.nameOfYourForm.nameOfYourSelect.selectedIndex=-1;" >
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9732367
if you post the code for your form page I will modify it accordingly.
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 9732383
Can you not just include an empty option element as the first choice?
<option></option>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9732398
... but in general, if you set the selectedIndex property of the SELECT to -1, it will display a blank default value.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 31

Expert Comment

by:seanpowell
ID: 9732412
Didn't know that... Is that fully cross-browser?

Thanks
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9732441
in IE and Netscape, yes ... including earlier versions.
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 9732445
Just did some tests - seems to work quite well :-)
0
 

Author Comment

by:RichardFox
ID: 9732557
bullseye! thanks kEk
0
 

Author Comment

by:RichardFox
ID: 9732660
Just a short note, I needed to do this with a couple of selects, so I used

<script language="javascript">

      window.onload = init;

      function init()
      {
            document.office2dealForm.typeSelect.selectedIndex   = -1;
            document.office2dealForm.resultSelect.selectedIndex = -1;
      }
</script>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now