I have this select
JSX:
<select className="form-control" onChange={this.onChange} value={this.props.value}>
{options}
</select>
with options being:
var options = this.props.options.map((option) => {
return (<option key={option.slug} value={option.slug} data-country={option.country} data-continent={option.continent}>{option.value}</option>);
});
But I can't access the selected data-country
of the option selected, since the value is accessed by e.target.value
, and e.target.dataset
is the dataset of the select
tag and not the option selected tag:
onChange: function(e) {
this.props.onChange(this.props.name, e.target.value, e.target.dataset.continent, e.target.dataset.country);
},
Is there a fix on this?
Thanks
e.target.options[e.target.selectedIndex]
, but trust me guys this approach works everywhere in any browser - native support. – Thankless