How to get selected value of dropdown in javascript (with jQuery example)

Introduction

We will explain hot to retrieve the selected element using javascript from the following html:

<select id="selector">
  <option value="1">Option 1</option>
  <option value="2" selected="selected">Option 2</option>
  <option value="3">Option 3</option>
</select>

To retrieve the value of the selected element use:

Plaing javacript

var e = document.getElementById("selector");
var strUser = e.options[e.selectedIndex].value;

If you need the text of the selected element use:

var e = document.getElementById("selector");
var strUser = e.options[e.selectedIndex].text;

Using jQuery

The first line will get the text content of the selected option and the second line the value.

$("#selector :selected").text(); 
$("#selector").val();