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

576
Views
Cómo pasar parámetros en onChange of html select

Soy un novato en JavaScript y jQuery. Quiero mostrar un combobox-A, que es un HTML <select> con su id y contenido seleccionados en el otro lugar en onChange().

¿Cómo puedo pasar el cuadro combinado completo con su id de selección y cómo puedo pasar otros parámetros en el fuego del evento onChange?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

 function getComboA(selectObject) { var value = selectObject.value; console.log(value); }
 <select id="comboA" onchange="getComboA(this)"> <option value="">Select combo</option> <option value="Value1">Text1</option> <option value="Value2">Text2</option> <option value="Value3">Text3</option> </select>

El ejemplo anterior obtiene el valor seleccionado del cuadro combinado en el evento OnChange .

over 4 years ago · Santiago Trujillo Report

0

Otro enfoque que puede ser útil en algunas situaciones es pasar el valor de la <option /> seleccionada directamente a la función de esta manera:

 function myFunction(chosen) { console.log(chosen); }
 <select onChange="myFunction(this.options[this.selectedIndex].value)"> <option value="1">Text 1</option> <option value="2">Text 2</option> </select>

over 4 years ago · Santiago Trujillo Report

0

Para saber cómo hacerlo en jQuery:

 <select id="yourid"> <option value="Value 1">Text 1</option> <option value="Value 2">Text 2</option> </select> <script src="jquery.js"></script> <script> $('#yourid').change(function() { alert('The option with value ' + $(this).val() + ' and text ' + $(this).text() + ' was selected.'); }); </script>

También debe saber que Javascript y jQuery no son idénticos. jQuery es código JavaScript válido, pero no todo JavaScript es jQuery. Debe buscar las diferencias y asegurarse de que está utilizando la adecuada.

over 4 years ago · Santiago Trujillo 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!