-1

I have this dropdownList:

  <Dropdown
                  isOpen={this.state.dropdownOpen[3]}
                  toggle={() => {
                    this.toggle(3);
                  }}
                >
                  <DropdownToggle className="my-dropdown" caret>
                    {" "}
                    {this.state.dropDownValue}
                  </DropdownToggle>
                  <DropdownMenu>
                    <DropdownItem productid="0">
                      {" "}
                      <div onClick={this.changeValue}>
                        PURE BLACK MAT BLUETOOTH
                      </div>
                    </DropdownItem>
                    <DropdownItem productid="1">
                      {" "}
                      <div onClick={this.changeValue}>
                        PLAYER BLACK MAT FILAIRE
                      </div>
                    </DropdownItem>
                    <DropdownItem productid="2">
                      {" "}
                      <div onClick={this.changeValue}>
                        PURE PLUS BLACK MAT MEMORY 128 G
                      </div>
                    </DropdownItem>
                    <DropdownItem productid="3">
                      {" "}
                      <div onClick={this.changeValue}>
                        PURE LIMITED CHROME GOLD MEMORY 256G
                      </div>
                    </DropdownItem>
                    <DropdownItem productid="4">
                      {" "}
                      <div onClick={this.changeValue}>
                        PURE GOLD MAT BLUETOOTH
                      </div>
                    </DropdownItem>
                    <DropdownItem productid="5">
                      {" "}
                      <div onClick={this.changeValue}>
                        PLAYER GOLD MAT FILAIRE
                      </div>
                    </DropdownItem>
                    <DropdownItem productid="6">
                      {" "}
                      <div onClick={this.changeValue}>
                        PURE PLUS GOLD MAT MEMORY 128 G
                      </div>
                    </DropdownItem>
                    <DropdownItem productid="7">
                      {" "}
                      <div onClick={this.changeValue}>GAME ONE WHITE</div>
                    </DropdownItem>
                  </DropdownMenu>
                </Dropdown>

And this onClickListener:

 changeValue(e) {
    console.log(
      "The selected productId is: ",
      e.currentTarget.getAttribute("productid")
    );
    //The selected productId is:  null
    this.setState({
      dropDownValue: e.currentTarget.textContent
    });
  }

I am trying to access the productid of the selected DropdownItem. But, for some reason the result is always null:

console.log( "The selected productId is: ", e.currentTarget.getAttribute("productid") ); //The selected productId is: null

Any idea what I've done wrong?

AG_HIHI
  • 1,705
  • 5
  • 27
  • 69

1 Answers1

0

I have fixed this by passing the attribute productid inside the div:

 <DropdownItem>
                      {" "}
                      <div productid="0" onClick={this.changeValue}>
                        PURE BLACK MAT BLUETOOTH
                      </div>
                    </DropdownItem>
AG_HIHI
  • 1,705
  • 5
  • 27
  • 69