Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 703
  • Last Modified:

<SELECT> with no default selection

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
RichardFox
Asked:
RichardFox
  • 4
  • 3
  • 2
1 Solution
 
knightEknightCommented:
<BODY onload="document.nameOfYourForm.nameOfYourSelect.selectedIndex=-1;" >
0
 
knightEknightCommented:
if you post the code for your form page I will modify it accordingly.
0
 
seanpowellCommented:
Can you not just include an empty option element as the first choice?
<option></option>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
knightEknightCommented:
... but in general, if you set the selectedIndex property of the SELECT to -1, it will display a blank default value.
0
 
seanpowellCommented:
Didn't know that... Is that fully cross-browser?

Thanks
0
 
knightEknightCommented:
in IE and Netscape, yes ... including earlier versions.
0
 
seanpowellCommented:
Just did some tests - seems to work quite well :-)
0
 
RichardFoxAuthor Commented:
bullseye! thanks kEk
0
 
RichardFoxAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now