Problems with default value for html combo box

Posted on 2007-10-09
Last Modified: 2011-09-20
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>                
Question by:mamadouthiam
    LVL 3

    Accepted 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.

    Author Comment


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



    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    745 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

    19 Experts available now in Live!

    Get 1:1 Help Now