Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

92
Vistas
Selecting value of inputs in react

I have an issue with a project i am working on where i want o select the value of an input element and save it. When ii write my code and console log it to see if it will get the correct value it always just give the value of the first value. I have my inputs in a parent element and i have 5 of them. this is my code:

<div className="number--container">
                <input type="button" value="1" onClick={btnClicked}></input>
                <input type="button" value="2" onClick={btnClicked}></input>
                <input type="button" value="3" onClick={btnClicked}></input>
                <input type="button" value="4" onClick={btnClicked}></input>
                <input type="button" value="5" onClick={btnClicked}></input>    

this is the function that handles the value retrieving:

 function btnClicked(){
    const value= document.querySelector("input").value
    console.log(value)
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

 function btnClicked(e){
    const value= e.target.value;
    console.log(value)
}

In react, html element should not be approached directly. If you want direct access, we recommend using "ref". https://reactjs.org/docs/refs-and-the-dom.html

about 4 years ago · Juan Pablo Isaza Denunciar

0

Normally in react we never use the plain javascript DOM manipulation api such querySelector;

 function btnClicked(event){
  const {value}= event.target;
  console.log(value)
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda