Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get drop down value

How to determine what is selected in the drop down? In Javascript.

like image 369
anonymous Avatar asked Oct 27 '10 01:10

anonymous


2 Answers

If your dropdown is something like this:

<select id="thedropdown">
  <option value="1">one</option>
  <option value="2">two</option>
</select>

Then you would use something like:

var a = document.getElementById("thedropdown");
alert(a.options[a.selectedIndex].value);

But a library like jQuery simplifies things:

alert($('#thedropdown').val());
like image 166
cambraca Avatar answered Oct 05 '22 22:10

cambraca


Use the value property of the <select> element. For example:

var value = document.getElementById('your_select_id').value;
alert(value);
like image 38
casablanca Avatar answered Oct 05 '22 21:10

casablanca