Skip to content Skip to sidebar Skip to footer

Get Value From Select List In Js

I know that this might be very simple question and I tried to find solutions in the web but I can't figure it... I have the following C# / ASPX code: SelectArea += '

Solution 1:

For example if you have

<selectid="myselect"><optionvalue="1">value1</option><optionvalue="2"selected="selected">value2</option><optionvalue="3">value3</option></select>

To get selected option do:

var selects = document.getElementById("myselect");
  var selectedValue = selects.options[selects.selectedIndex].value;// will gives u 2var selectedText = selects.options[selects.selectedIndex].text;// gives u value2

Sample JsFiddle

Solution 2:

Try with this

var el = document.getElementById("area");
var selectedArea = el.options[el.selectedIndex].value;

Solution 3:

Try :

var myList = document.getElementById("area");
var selectedValue = myList.options[myList.selectedIndex].value;
var selectedText = myList.options[myList.selectedIndex].text;

Post a Comment for "Get Value From Select List In Js"