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

90
Views
javascript selecciona la segunda opción automáticamente?

¿Cómo puedo usar javascript para seleccionar automáticamente el valor de opción 2? Pero tengo y como la misma 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

Después de resolver el problema con las ID (cambiar las ID duplicadas), si desea seleccionar por valor, simplemente asigne en el nodo de select :

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

asumiendo que desea seleccionar <option value="2">Color 02</option> y la id del nodo select es "594951-Cor" .

El "2" es el valor de la `opción, no el índice.

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!