Learn how you can easily get the selected value from the dropdownlist using Javascript.

Dropdownlist contain a list of text which allows the website user to select from the options. When user select an option we would want to know what they have selected. If you wanted to use Javascript code to find out, here is the code:

Here is the Demo



CODE:

<select id="ddlOptions">

<option value="Apple">Appleoption>

<option value="Orange" selected="selected">Orangeoption>

<option value="Pear">Pearoption>

<option value="Strawberry">Strawberryoption>

<option value="Paw Paw">Paw Pawoption>

select>

br>

 

<script type="text/javascript">

function GetOptions()

{

var e = document.getElementById("ddlOptions");

var strOptions = e.options[e.selectedIndex].value;

 

alert("You have selected " + strOptions + "." );

}

script>

 

<button type="button" onclick="Javascript:GetOptions()">

Get Selected Valuebutton>

Now give it a go and see if you can get it done.

 

 
* iOS Development * OS X * Product Review