Is it possible to call a JS function when a specific a item is selected from dropdownlist?
2 Answers
HTML:
<select id="menu" name="menu">
<option value="something">Click here</option>
<option value="nothing">Not this</option>
</select>
JS:
document.getElementById('menu').onchange = function() {
if (this.options[this.selectedIndex].value === 'something') {
// Do something
}
};
Change "something" to whatever value you want.
1 Comment
markiz
one more little question, with onchange event there is a problem with re-selecting same item. If I try to select the same item event, the function won't get triggered. How to fix that?