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

152
Views
Cómo recuperar el valor de la opción seleccionada de una selección creada dinámicamente en una tabla

Estoy creando dinámicamente una lista desplegable en una tabla y quiero recuperar el valor del elemento seleccionado. Puedo obtener el valor de otros elementos (p. ej., entrada); sin embargo, el menú desplegable me tiene perplejo. En el siguiente código, la fecha de inicio es correcta, sin embargo, parRating siempre es 1 (el primer valor en la selección).

Nota: quiero el valor (parIdArray) no el val (parRatingArray).

HTML para crear:

 html += "<td style='width : 1%; white-space: nowrap;'><select name='parRating'>" for (let i = 0; i <= paraArray; i++) { if (this.parRating == parRatingArray[i]) { // set the current option to this.parRating html += "<option selected name='parRatingOption' value='" + parIdArray[i] + "'>" + parRatingArray[i] + "</option>" }else { html += "<option name='parRatingOption' value='" + parIdArray[i] + "'>" + parRatingArray[i] + "</option>" } }; html += "</select></td>"; if (this.patparStartDate == null) { html += "<td style='width : 1%; white-space: nowrap;'><input type='date' name='startDate' value=''></td>"; }else { html += "<td style='width : 1%; white-space: nowrap;'><input type='date' name='startDate' value='" + this.patparStartDate + "'></td>"; }

HTML para recuperar valores:

 var parRating = $(this).parents('tr:first').find('option[name="parRatingOption"]').value; alert("parRating: " + parRating);//always 1 var startDate = $(this).parents('tr:first').find('input[name="startDate"]').val();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solo necesita apuntar a la opción seleccionada en su código anterior usando jQuery : selector seleccionado :

También necesita usar .val() para obtener el valor de la opción, no el atributo de value en jQuery

Prueba este código a continuación:

 var parRating = $(this).parents('tr:first').find('option[name="parRatingOption"]:selected').val();
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!