Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:22:53+00:00 2026-05-22T17:22:53+00:00

I have a select element like this <select name =cars> <option value=frd> Ford </option>

  • 0

I have a select element like this

<select name ="cars">
  <option value="frd"> Ford </option>
  <option value="hdn"> Holden </option>
  <option value="nsn"> Nissan </option>
</select>

I want to set selected to “Holden” with javascript without selected by value. how can I achieve this?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:22:54+00:00Added an answer on May 22, 2026 at 5:22 pm

    update after comment

    Use the following to find the option by text and select it

    var optionlist = document.getElementById('cars').options;
    
    for (var option = 0; option < optionlist.length; option++ )
    {
      if (optionlist[option].text == 'Holden')
      {
        optionlist[option].selected = true;
        break;
      }
    }
    

    demo at http://jsfiddle.net/gaby/vQhfq/


    original

    When there is no value attribute specified for option elements, they assume the value to be the text.

    I would suggest you use an id, so you can easily find the element.

    Html

    <select name ="cars" id="cars">
      <option> Ford </option>
      <option> Holden </option>
      <option> Nissan </option>
    </select>
    

    javascript

    document.getElementById('cars').value = 'Holden';
    

    (make sure you run this code, after the select element is created)

    demo at http://jsfiddle.net/gaby/Pwb5u/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some html element like these: <table id=myTable></table> <select name=mySelect> <option value=1>1</option> <option
I have a select element. <select class='cSelectType'> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> <option
<select id=townid name=townid> <s:iterator value=townsForLanding> <option value=<s:property value=id/>><s:property value=name/></option> </s:iterator> </select> I have a
I have a html element (like select box input field) in a table. Now
I have a table. In this table have select element. How can I find
I have a select form element with 5 options. If option 2 is selected
HI! I have a problem with changing the name of a select element. I
i have an xml file that looks something like this <library> <book name=ABC> <chapter
I have some message elements like this... <span class=error message>Whoops! Don't forget your name.</span>
I have an xml file like this: <uploads> <upload> <name>asd</name> <type>123</name> </upload> <upload> <name>qwe</name>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.