109

I have a drop down that has an 'ID, Name' Pair.

Example

Jon Miller
Jim Smith
Jen Morsin

Jon MIller has ID of 101
Jim Smith has ID of 102
Jen Morsin has ID of 103

When I do the followng:

var arNames = $('#Crd').val() 

and I select Jon Miller, I get 101. I'd like to get Jon Miller though.

Prashanth Benny
  • 1,523
  • 21
  • 33
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
  • Check out http://stackoverflow.com/questions/1643227/jquery-get-selected-text-from-dropdownlist – Franz Jan 23 '12 at 20:50

11 Answers11

211

$('#Crd').val() will give you the selected value of the drop down element. Use this to get the selected options text.

$('#Crd option:selected').text();
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
14

The best way is to use:

$("#yourid option:selected").text();

Depending on the requirement, you could also use this way:

var v = $("#yourid").val();
$("#yourid option[value="+v+"]").text()
Andy T
  • 10,223
  • 5
  • 53
  • 95
Sandeep Pal
  • 2,067
  • 1
  • 16
  • 14
6

This has worked for me!

$('#selected-option option:selected').val()

Hope this helps someone!

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
5

If you're using a <select>, .val() gets the 'value' of the selected <option>. If it doesn't have a value, it may fallback to the id. Put the value you want it to return in the value attribute of each <option>

Edit: See comments for clarification on what value actually is (not necessarily equal to the value attribute).

Ansel Santosa
  • 8,224
  • 1
  • 28
  • 39
4

Try this:

var text = $('#YourDropdownId').find('option:selected').text();
fbarikzehy
  • 4,885
  • 2
  • 33
  • 39
4

Another option:

$("#<%=dropDownId.ClientID%>").children("option:selected").val();
Pang
  • 9,564
  • 146
  • 81
  • 122
3
var sal = $('.selectSal option:selected').eq(0).val();

selectSal is a class.

falsetru
  • 357,413
  • 63
  • 732
  • 636
0

$('.leave_response').on('change', function() {
    var responseId = $(this).val();
    console.log(responseId);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td>
    <select class="leave_response" name="leave">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
    </select>
</td>
Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
Yasas Malinga
  • 29
  • 1
  • 4
0

Pass the id and hold into a variable and pass the variable where ever you want.

var temp = $('select[name=ID Name]').val();

0

You can have text value of #Crd in its variable .

$(document).on('click', '#Crd', function () {
     var Crd = $( "#Crd option:selected" ).text();
});
Hesam Moosapour
  • 510
  • 5
  • 12
0

As has been pointed out ... in a select box, the .val() attribute will give you the value of the selected option. If the selected option does not have a value attribute it will default to the display value of the option (which is what the examples on the jQuery documentation of .val show.

you want to use .text() of the selected option:

$('#Crd option:selected').text()

lhagemann
  • 1,268
  • 11
  • 13