0
var colDdl = $('#ColumnSelection').text();
var filterDdl = $('#FilterOptions').text();

Above is my code where I am trying to get the text of the selected dropdown list item. If i use the .val(), I get the value(1,2,3 etc). How do I get the text. Above code gives me null in the respective variables colDdl and filterDdl.

user2998990
  • 970
  • 5
  • 18
  • 36

4 Answers4

1

Try this I hope this will help you

var colDdl =  $("#ColumnSelection option:selected").text();
var filterDdl = $("#FilterOptions option:selected").text();
user3386779
  • 6,883
  • 20
  • 66
  • 134
1

Use this

var colDd1 = $('#ColumnSelection option:selected').text();
var filterDdl = $('#FilterOptions option:selected').text();
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41
1
<select id="ColumnSelection">
  <option value="1">Text 1</option>
  <option value="2">Text 2</option>
  <option value="3">Text 3</option>
</select>

In script side

var colDdl = $("#ColumnSelection option:selected").text();

you can apply same method in

var filterDdl = $('#FilterOptions option:selected').text();
Elby
  • 1,624
  • 3
  • 23
  • 42
1

Try This, This will help you...

$(document).ready(function(){
    $('#gd').click(function(){
       alert($('#cars').val());
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id='cars' name="cars" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<button id="gd">Get Value</button>

Using val() you get the values of the selected options, if you use multiple drop down list you will get the result in array.

Pradeep Rajput
  • 724
  • 7
  • 11