COBIZ webdevelopment
COBIZ webdevelopment

Reputation: 575

jQuery Chosen - get (multiple) selected labels (not the value)

How to get the selected option's text from the Chosen select? So not just the .val() but the option label/text

Upvotes: 11

Views: 39730

Answers (9)

Sinan ÇALIŞKAN
Sinan ÇALIŞKAN

Reputation: 243

You can check this for single select.

<select class="chzn-select" id="CHSNID" onchange="alert($('#CHSNID_chzn a span').text())">

Or

$(function(){
     $('#CHSNID').change(function(){
     var text = $('#CHSNID_chzn a span').text();
     console.log(text);
   }); 
});

Upvotes: 2

hayoeu
hayoeu

Reputation: 41

The below will get the label & here is a JSFiddle showing how to get the chosen dropdown's value or label field using the latest chosen jquery plug-in version 1.4.2. https://jsfiddle.net/hayoeu/4usazfdm/2/

$(".chzn-select option:selected").text();

Upvotes: 0

Daniel
Daniel

Reputation: 455

The only way that work for me, was doing something like this:

var options = $("#ddl option:selected");

var values = $.map(options, function (option) {
    return option.text;
});

Where values is an array.

Hope that it helps...

Upvotes: 2

vivek takrani
vivek takrani

Reputation: 4010

none of the above answers worked for me and so after searching a lot finally got the answer to retrieve the "label" value of the selected element

$("#your_select_id option:selected").attr('label');

Upvotes: 0

kravits88
kravits88

Reputation: 13049

To get text values for multiple select:

<select id="sTags" class="chosen" multiple />

Jquery:

    $.map($("#sTags_chosen").find(".search-choice span"), function (option) {
        return $(option).text()
    });

Upvotes: 1

Mohamed Sabirulla
Mohamed Sabirulla

Reputation: 29

//Below code return name of the drop downn

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

//Below code return value of the drop downn

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

Upvotes: 3

Adesh M
Adesh M

Reputation: 444

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

Above jQuery statement should do it for.

Upvotes: 6

COBIZ webdevelopment
COBIZ webdevelopment

Reputation: 575

Used: $("#list option[value='"+id+"']").text(); To retrieve the label of the selected value

Upvotes: 12

123
123

Reputation: 525

You can simply use this to get the label.

$('.result-selected').html() 

or

$('.options option:selected').html() 

Upvotes: 14

Related Questions