0

In my application I have list of text boxes.For reflecting changes in text boxes I am calling handleChange function call. when I send third parameter(index) to function, e value becomes undefined.

Html:

<div className="col-md-2">
    <Input type="select" placeholder="select"
     wrapperClassName="col-xs-12" value={this.props.lang}
     onChange={this.handleChange.bind(this, 'language', index)}>
         <option value="en">en</option>
         <option value="de">de</option>
     </Input>
</div>

Call:

  handleChange(name, e) {
    this.state.description[0][name] = e.target.value;
    this.setState({description: this.state.description});
    console.log('---updated--', this.state);
  }

How to send another parameter to handleChange function call on onChange event? How can I send multiple parameters?

Anusha Nilapu
  • 1,243
  • 8
  • 24
  • 36

1 Answers1

0

First of all, you should never change state directly as you did on the first line of your handleChange method.

The onChange callback is not intended to be called with additional parameter, it's a callback, so just pass a function, not a function call. You're 'language' and index parameters should be accessible from elsewhere within your component scope.

Pierre Criulanscy
  • 8,726
  • 3
  • 24
  • 38