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

99
Views
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 answers
Answer question

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 Report

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