Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda