Reputation: 51
why does the following simple select button work on mozilla but not on chrome or safari. and when i say work i mean, the getHistory function gets called successfully on mozilla but not on other browsers.
<select id="history" style="width: 10%; margin-top: 150px; margin-left: 1200px;" >
<option>History</option>
<option onclick="getHistory(0.5);"> 2 weeks </option>
<option onclick="getHistory(1);"> 1 month </option>
<option onclick="getHistory(3);"> 3 months </option>
<option onclick="getHistory(6);"> 6 months </option>
<option onclick="getHistory(0);"> Adam and Eve </option>
<option onclick="getCurrent();"> Current </option>
</select>
Upvotes: 0
Views: 55
Reputation: 557
JavaScript onclick doesn't work on options in IE and Chrome. You can refer this link for more detail: onclick on option tag not working on IE and chrome
You can bind value in options and fetch them on change event of select. Sample code below:
<select id="history" style="width: 10%; margin-top: 150px; margin-left: 1200px;" onchange="selectChangeEvent(this.value)">
<option value="History">History</option>
<option value="0.5">2 week</option>
<option value="1">1 month</option>
<option value="3">3 months</option>
<option value="6">6 months</option>
<option value="3">Adam and Eve </option>
<option value="Current">Current</option>
</select>
//JavaScript code
function selectChangeEvent(_selectedVal) {
if(_selectedVal == "Current") {
getCurrent();
}
else {
getHistory(_selectedVal);
}
}
Upvotes: 2