We can read the selected option of a drop down list box by using onChange event trigger. The onChange event will trigger one JavaScript function and we will try to read the selected item by using getElementById
<select id=s1 name=no_year onChange="show_date()";>
....
</select>
Here is the code
<html>
<head>
<title>Demo Project on JavaScript listbox onChange</title>
</head>
<script type="text/javascript">
function show_date(){
document.getElementById("msg3").innerHTML= document.getElementById("s1").value;
return true;
}
</script>
</body>
<body>
<select id=s1 name=no_year onChange="show_date()";>
<option value=Jan>January</option>
<option value=Feb>February</option>
<option value=March>March</option>
<option value=April>April</option>
<option value=May>May</option>
</select>
<div id='msg3'></div>
</body>
</html>
← Subscribe to our YouTube Channel here