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

122
Views
Obtener grupo de opciones seleccionado en JavaScript

Tengo la siguiente etiqueta de select con dos optgroup .

 <select id="linkSelector" class="form-control" onchange="linkDropDown();"> <optgroup label="Input"> <option value="default">Road type</option> <option value="lanes">Lanes</option> <option value="length">Length</option> <option value="speed">Speed</option> </optgroup> <optgroup label="Ouput"> <option value="congestion">Congestion</option> <option value="speed_output">Speed</option> <option value="travel_time">Travel Time</option> </optgroup> </select>

Me gustaría ejecutar myFuncton() según el grupo de optgroup seleccionado. Por ejemplo, si uno de los valores desplegables pertenece a <optgroup label="Input"> , ejecute myFunction() .

Intenté esto:

 var linkSelector = document.getElementById('linkSelector') opt = linkSelector.getElementsByTagName('optgroup') if (opt[0].label =='Input'){ myFunction() }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Una forma de hacerlo sería obtener la opción seleccionada para el campo de selección y luego averiguar su etiqueta principal.

 var label = document.getElementById('linkSelector').selectedOptions[0].parentElement.label; if (label === "Input") { myFunction(); }
about 4 years ago · Juan Pablo Isaza 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!