Search code examples
javascriptjquerysharepoint-2010

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();

Solution

  • You could use-

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

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