Web Analytics Made Easy -
StatCounter Resetting A Selection Menu - CodingForum

Announcement

Collapse
No announcement yet.

Resetting A Selection Menu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resetting A Selection Menu

    Hi,

    I have a <select> menu on one of my pages that has 20 options. I would like for it to reset itself once a user picks an option so that if they come back and pick another option, the selection menu will show <option>- Please Select -</option> instead of the option that was just selected. I've tried focus(), but that doesn't help. I have some experience with JS, but not enough to know how this would be achieved.

    I look forward to your response!

    Thanks,

    7079

  • #2
    Use the selectedIndex property of the select element.

    This script gets a refrence to the select element, then uses the selectedIndex property to reset the selected option.
    PHP Code:
    <html>
        <
    head>
            <
    title>Reset a selection box.</title>
        </
    head>
        <
    body>
            <
    form name="myForm" id="myForm" action="http://www.vortexcortex.com">
                
    Industry:
                <
    select name="mySelect" id="mySelect">
                    <
    option value="" selected="selected">- Select an option -</option>
                    <
    option value="IT">InfoTech.</option>
                    <
    option value="CS">CustService</option>
                </
    select>
                <
    script type="text/javascript">
                    
    document.myForm.mySelect.selectedIndex=0//set the selection to index 0.
                
    </script>
                <
    input type="submit">
            </
    form>
        </
    body>
    </
    html

    Comment


    • #3
      That's exactly what I was looking for, except I needed to use it like so:

      Code:
      <select name="mySelect" id="delims" onchange="insertHTML(),document.myForm.mySelect.selectedIndex=0;">
      Thanks for the help, it's hard to remember the syntax, I have certain JS that I use and from time to time I need different JS which gives me a hard time.

      I love this forum, the JS developers here are always willing to help!

      7079

      Comment

      Working...
      X