Showing posts with label show selected value using javascript. Show all posts
Showing posts with label show selected value using javascript. Show all posts

Sunday, March 9, 2014

how to show the value that is selected in drop down menu by the user using javascript

 <select name="place" id="place" onchange="spk();">
<option></option>
<option value="1">California</option>
<option value="2">New York</option>
<option value="3">Las Vegas</option>
<option value="4">Texas</option>
<option value="5">Ohio</option>
</select>

<div id="speak"></div>

<script>
function spk(){
    var b = document.getElementById("place");
    var c = b.options[b.selectedIndex].value; // this shows the selected option's value
    var d = b.options[b.selectedIndex].text; // this shows the selected option's text
    var e = "You have selected ";
    document.getElementById("speak").innerHTML = e.concat(d);
}
</script>