Avatar of brianhu
brianhu
Flag for United States of America asked on

How do I clear drop-down selection so user can make any selection from same drop-down menu?

How do I clear drop-down selection when choice is made so user can immediately make any or same selection from same drop-down (choice made launches new browser window)?

My example URL:
http://www.imshome.com/mdrive23plus_mdi.html#pn

I would like user to be able to easily choose any option from any of 3 drop-downs, whether same option already selected or not. Right now, selection does not clear and selection must be different to launch window with info. JavaScript for this?
JavaScriptScripting Languages

Avatar of undefined
Last Comment
HonorGod

8/22/2022 - Mon
brianhu

ASKER
Clarified question.
HonorGod

Locate the select element, and change the selectedIndex value to 0
<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Pick and Clear </title>
<script type='text/javascript'>
  function doit( obj ) {
    if ( obj ) {
      if ( obj.nodeName == 'SELECT' ) {
        alert( 'Pick: ' + obj.options[ obj.selectedIndex ].text );
        obj.selectedIndex = 0;
      } else {
        alert( 'select object expected, but found: ' + obj.nodeName );
      }
    } else {
      alert( 'select object required, but not specified' );
    }
  }
</script>
</head>
<body>
<form action=''>
  <select id='sel' onchange='doit(this)'>
  <option>Make a selection</option>
  <option>One</option>
  <option>Two</option>
  </select>
</form>
</body>
</html>

Open in new window

brianhu

ASKER
HonorGod,

Sorry, I'm not following -
When I change onchange=  to  onchange="doit(this)" or onchange="doit()", I just get the default messages without sending value to php script. Please see my form tag below (without change above):

(JavaScript function is in head section as given.)

Thank you!
<form action="PHP/connectivity.php" method="get" target="_blank" class="style15">
                           <div align="center"><span class="style14"><em style="font-size:11px;">P/N: &nbsp;</em> MDI1</span>
                             <select name="mdrivepn" id="mdrivepn" onchange="this.form.submit()" style="font-size:10px; font-weight:bold; letter-spacing:.05em;">
                               <option selected="selected">Select</option>
                               <option value="MDI1FRD23*7">F RD</option>
                               <option value="MDI1FRL23*7">F RL</option>
                               <option value="MDI1FCB23*7">F CB</option>
                               <option value="MDI1PRD23*7">P RD</option>
                               <option value="MDI1PRL23*7">P RL</option>
                               <option value="MDI1PCB23*7">P CB</option>
                             </select>
                             <span class="style14"> 23*7</span> </div>
                      </form>

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
HonorGod

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
brianhu

ASKER
HonorGod,
Yes, having onchange="this.form.submit(); this.selectedIndex=0" (both commands) in my form tag was all I needed. Thanks for your help!
But God demonstrates His own love toward us, in that while we were still sinners, Christ died for us.  -Romans 5:8   What a glorious God!

Brian Hurst
brian.hurst@sbcglobal.net
HonorGod

You are very welcome.  I'm glad to have been able to help.

Good luck & have a blessed day.

p.s. Thanks for sharing the verse