Solved

<SELECT> with no default selection

Posted on 2003-11-12
9
682 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

828 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