0

I have read so many posts that i think I have read so many and got confused as it seems there are many ways to do what i need. This is my component

class InputForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = { dropdown: 'RTS', value: '' };

    this.handleChange = this.handleChange.bind(this);
    this.handleDropdown = this.handleDropdown.bind(this);

    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event) {
    this.setState({ value: event.target.value });
  }

  handleDropdown(event) {
    this.setState({ dropdown: event.target.dropdown });
  }

  handleSubmit(event) {
    event.preventDefault();
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit} className='flex'>
        <select value={this.state.dropdown} onChange={this.handleDropdown} className='py-2 px-3 mr-2 rounded'>
          <option value='RTS'>RTS</option>
          <option value='RTB'>RTB</option>
          <option value='BH'>BH</option>
          <option value='MPC'>MPC</option>
          <option value='MPC_DSP'>MPC_DSP</option>
        </select>

        <input
          type='text'
          value={this.state.value}
          onChange={this.handleChange}
          className='py-2 px-3 mr-2 rounded'
          placeholder='Log Name...'
        />

        <Btn onClick={() => getData(this.state.dropdown, this.state.value)}>Generate</Btn>
      </form>
    );
  }
}

export default InputForm;

When changing the state of value={this.state.dropdown} i am getting undefined. Have i set everyting correctly?

1 Answer 1

1

In your handleDropdown function you need to retrieve the value from event.target.value instead of event.target.dropdown:

handleDropdown(event) {
  this.setState({ dropdown: event.target.value });
}
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect...i was close but not there! haha Thanks for fixing it...it was driving me a little mad

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.