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

135
Views
reactjs input return undefined

Input returning undefined, I also added onChange function to the input, this.state.quantity returns undefined in the console

OrderMed.js:

export default class OrderMed extends Component {
  constructor(props){
    super(props);
    this.state = {
      Meds: [],
      quantity: '',
      id:''
    }
    this.onChange = this.onChange.bind(this);
  }
  onChange(e) {
    this.setState({quantity: e.target.quantity})
  }
render() {
    return ( 
...
<form >
 <input min={1} placeholder='quantity' type='number' value={this.state.quantity} onChange={this.onChange} id="quantity"></input>
 <button onClick={() => console.log(this.state.quantity)} id='btn-color1' class="btn btn-color ml-2 px-3 mb-2 w-1">&#10003;</button> 
</form>
...
 )
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you just should set event.target.value in onChange function like this:

onChange(e) {
    this.setState({quantity: e.target.value})
  }
about 4 years ago · Juan Pablo Isaza Report

0

you should go for arrow functions rather than the old fashion ones it reduces complexities and you missed the value of the target element

export default class OrderMed extends Component {
  constructor(props){
    super(props);
    this.state = {
      Meds: [],
      quantity: '',
      id:''
    }
  }
  onChange = (e) => {
    const quantity  = e.target.value;

    this.setState({quantity})
  }
render() {
    return ( 
...
<form >
 <input min={1} placeholder='quantity' type='number' value={this.state.quantity} onChange={this.onChange} id="quantity"></input>
 <button onClick={() => console.log(this.state.quantity)} id='btn-color1' class="btn btn-color ml-2 px-3 mb-2 w-1">&#10003;</button> 
</form>
...
 )
}
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!