Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
javascript select the second option automatically?

How can I use javascript, to automatically select Option value 2? But I have and as the same id ..

var index = 1; /* option do select*/
document.getElementById("594951-Cor").options.selectedIndex = index;
<div id="594951-Cor" name="594951-Cor">

<select id="594951-Cor" name="594951-Cor" class="">
<option value="0">Selecione...</option>
<option value="1">Color 01</option>
<option value="2">Color 02</option>
</select>

</div>

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

After solve the problem with ID's (change the duplicated id's), if you want to select by value, just assign on the select node:

document.getElementById("594951-Cor").value = "2";

assuming that you want to select <option value="2">Color 02</option> and the id of the select node is "594951-Cor".

The "2" is the value of the `option, not the index.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!