Solved

<SELECT> with no default selection

Posted on 2003-11-12
9
658 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

706 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

18 Experts available now in Live!

Get 1:1 Help Now