Wasim
Wasim

Reputation: 724

Get Selected Option Text of SELECT using JQuery

I have dynamically created option where all values in option are coming from share point list . Now I want to get the text of selected option . I tried few ways but I was not able to get

Code for getting data from list

$("#ddlIncrementType").append(
  $("<option></option>")
    .data("incrementLevel", results[increment].IncrementLevel)
    .val(results[increment].Title)
    .html(results[increment].Title)
);

Code where my option append

<div class="Increment">
    <label for="sel1">Increment Type:</label>
    <select disabled class="form-control" id="ddlIncrementType">
        <option></option>
    </select>
</div>

I want to get the text of Selected Option Suppose in list there are three options

  1. Item One
  2. Item Two
  3. Item Three

I want exactly text Anyone who can help ?

I tried it but does't not worked !

var value = $("#ddlIncrementType").find(":selected").val();

var selectedText = $("#mySelect option:selected").html();

var value = $("#ddlIncrementType").find(":selected").text();

Upvotes: 2

Views: 2314

Answers (2)

Ranjeet
Ranjeet

Reputation: 579

You can try this:

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

Upvotes: 5

Anshu Sharma
Anshu Sharma

Reputation: 170

You could use-

$(document).on('change', "#ddlIncrementType", function(){
    var value = $(this).text();
    alert(value);
});

Also you should not be using disabled for your <select>

Upvotes: 1

Related Questions