Change event on <select>

adivasile picture adivasile · Mar 17, 2010 · Viewed 14.9k times · Source

With Mootools, if I attach a change event listener on a <select> how do I access the option that was selected. I would like the actual element and not just the value.

$('select').addEvent('change',function(event) {
    //??
});

Answer

Anurag picture Anurag · Mar 17, 2010

Either of these will work:

find by :selected pseudo selector in descendants

this.getElement(':selected');

get first selected value

this.getSelected()[0];

pure javascript, use the selectedIndex property

this.options[this.selectedIndex];