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

  <select id="myselect">
      <option value="1">value1</option>
      <option value="2" selected="selected">value2</option>
      <option value="3">value3</option>
  </select>

To get selected option do:

  var selects = document.getElementById("myselect");
  var selectedValue = selects.options[selects.selectedIndex].value;// will gives u 2
  var 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"