[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2967
  • Last Modified:

Problems with default value for html combo box

I have a dropdown form on one of my html pages and I want the default value that appears (when the page loads) to be the first option listed below (Information for ...).  Currently, the default appears to be the "Youth and Educators" option.  Any ideas on how to set the default for the form? I tested this previously and it seemed as if the first option was the default but I can't seem to get it to work right anymore

              <select class="audiencebox" onChange="var val = this.options[this.selectedIndex].value; if (val) location=val">
                  <option value="">Information for ...</option>                          
                  <option value="/about/consumers.html" selected>Consumers</option>
                          <option value="/about/government.html" selected>Government</option>
                          <option value="/about/applicants.html" selected>Grant Applicants</option>  
                          <option value="/about/media.html" selected>Media</option>
                          <option value="/about/small_businesses.html" selected>Small Businesses</option>
                          <option value="/about/youth.html" selected>Youth and Educators</option>                
1 Solution
The word "selected" to an html "<option>" tag delineates the one you want to be chosen as the default. Since you have all of them be "selected" the browser will just choose the last one. To fix this, remove "selected" from all buy the one that you want to be the default.


<option value="/about/government.html" selected>Government</option>

would become

<option value="/about/government.html">Government</option>

and so on and so forth.
mamadouthiamAuthor Commented:

Fantastic.  I think I was doing a copy and paste on the option code and had not even seen that.



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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now