akash
akash

Reputation: 173

How to get the selected value of @html.dropdownlist here?

I am having this on my client side console

enter image description here

I want to extract only 2015 which is currently selected option. How is it possible?

Upvotes: 1

Views: 47

Answers (2)

SamGhatak
SamGhatak

Reputation: 1493

EDITED

According to this link,

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

This should do.

Upvotes: 2

Christos
Christos

Reputation: 53958

You could try this:

var selectedOptionText = $("YearIn option:selected").text();

For instance check the following snippet:

$(function(){
  $("#YearIn").change(function(){
    alert($("#YearIn option:selected").text());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="YearIn">
  <option val="1">One</option>
  <option val="2">Two</option>
  <option val="3">Three</option>
  <option val="4" selected>Four</option>
  <option val="5">Five</option>
</select>

Upvotes: 3

Related Questions