Selected Index changed event in javascript for html control

RMN picture RMN · Oct 21, 2012 · Viewed 23.6k times · Source

I have an HTML control:

<select id="grade">

I want to get the selected value of dropdown on selected Index changed event.

I tried to add following code which would be called on drop down selection change, but seems it doesnot work. Any other suggestion ?

$("#grade").on('change', function() { 
alert("hi"); 
});

Also, how can I get the selected value in Java Script.

Answer

Sylvain Martens picture Sylvain Martens · Oct 10, 2016

Here is an alternative for those who don't need jQuery:

<select id="grade" onchange="OnGradeChanged(this.value);">
     <option value="1">1</option>
     <option value="2">2</option>
</select>
<script>
function OnGradeChanged(value){
     alert(value);
}
</script>