user944513
user944513

Reputation: 12729

why onchange is not fired in react js dropdown?

why onchange is not fired in react js dropdown? I already bind my function this context or this. here is my code https://codesandbox.io/s/m2qjz6k48

onDropDownSelected = event => {
    let index = event.nativeEvent.target.selectedIndex;
    //event.nativeEvent.target[index].text;
    if (index !== 0) {
      let fields = this.state.fields;
      fields["selectedRole"] = this.state.roles[index];
      this.setState({ fields });
    }
  };

HTML

<Input
              type="select"
              name="select"
              onChange={this.onDropDownSelected.bind(this)}
              className="block__login_formGroup_input"
              //  value={this.state.fields["selectedRole"]}
              id="exampleSelect"
            >
              <option>Select Role</option>
              {this.createRolesDropDown()}
            </Input>

Upvotes: 1

Views: 78

Answers (1)

nilesh bhingaradiya
nilesh bhingaradiya

Reputation: 311

I just checked your code and see that onChange is fired dropdown option change I just update some code so you can check it below link, you can check this https://codesandbox.io/s/00pxl9mmol

Upvotes: 1

Related Questions