Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

<SELECT> with no default selection

Posted on 2003-11-12
9
Medium Priority
?
698 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 200 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
Industry Leaders: 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

Technology Partners: 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!

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

722 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