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

329
Views
¿Cómo obtener el valor de la etiqueta de entrada que cambia?

Básicamente, escribí esta función en JavaScript:

 <script> function getVal(value) { console.log(value); } </script>

Y esta es mi etiqueta de entrada HTML:

 <input onchange="getVal(this.value)" type="text" id="unit" />

Espero obtener el valor de este elemento impreso en la consola (que no lo hago). No estoy escribiendo manualmente el valor del elemento, sino configurándolo con este código:

 <script> var table = document.getElementById('table'); for(var i = 1; i < table.rows.length; i++) { table.rows[i].onclick = function() { //rIndex = this.rowIndex; document.getElementById("unit").value = this.cells[0].innerHTML; }; } </script>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Acabo de cambiar el índice a partir de 0 en lugar de 1 cuando recorría las filas de la tabla y agregué la llamada dispatchEvent para activar el evento en el texto de entrada para que se ejecute su controlador.

Por favor, hágamelo saber si hay algo que no entendí correctamente en su pregunta.

 function getVal(value) { console.log(value); } let table = document.getElementById('table'); for(var i = 0; i < table.rows.length; i++) { table.rows[i].onclick = function() { let unit = document.getElementById("unit"); unit.value = this.cells[0].innerHTML; unit.dispatchEvent(new Event('change')); }; }
 table#table{ width: 100%; } table#table tr:hover{ background: lightgray; cursor: pointer; } table#table tr td{ border: solid 1px black; }
 <input onchange="getVal(this.value)" type="text" id="unit" /> <table id="table"> <tr> <td>Row1</td> </tr> <tr> <td>Row2</td> </tr> <tr> <td>Row3</td> </tr> </table>

about 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!