I suppose to have some value from <button> tag but it is undefined when I click the button. What am I doing wrong?
I use function(e) to get attributes and then e.value = undefined.
runTest(elem){
let url = 'someUrl';
let path = elem.value;
console.log(path);
$.post(url, {
path: path
}, function(data, status){
alert('Data: ' + data + "\nStatus: " + status);
});
}
render() {
return (
<div className='wrapper'>
<div className="btn-group dropright">
<button type="button" className="btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Wraith
</button>
<div className="dropdown-menu">
<button className="dropdown-item" value='someValue' onClick={this.runTest}>Get value</button>
</div>
</div>
</div>
);
}
onClicklistener receiveseventobject as argument, not DOM element.propsof your component and do something like<button className="dropdown-item" value={this.props.someValue} onClick={this.runTest}>Get value</button>