Solved

<SELECT> with no default selection

Posted on 2003-11-12
9
691 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
[X]
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
  • 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
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!

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow a tab area under the contents 1 37
How do I show a login page over the login page? 5 59
.CSS HTML Help 3 58
Excel to HTML macro with inserting lines 14 51
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Find out what you should include to make the best professional email signature for your organization.
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 learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

734 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