Access our premium support and let us know your problems, we will help you solve them.

0
No products in the cart.
  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 31 total)
  • Author
    Posts
  • #9355
    blankhaddar
    Participant

    How can I get the selected text (not the selected value) from a drop-down list in jQuery?

    #9378
    blankzarni
    Participant
    var someName = "Test";
    
    $("#<%= ddltest.ClientID %>").each(function () {
        $('option', this).each(function () {
            if ($(this).text().toLowerCase() == someName) {
                $(this).attr('selected', 'selected')
            };
        });
    });
    

    That will help you to get right direction. Above code is fully tested if you need further help let me know.

    #9385
    blankrafael
    Participant
    $("option:selected", $("#TipoRecorde")).text()
    
    #9383
    blankneeraj
    Participant

    $("#DropDownID").val() will give the selected index value.

    #9382
    blankkamrul
    Participant

    For the text of the selected item, use:

    $('select[name="thegivenname"] option:selected').text();
    

    For the value of the selected item, use:

    $('select[name="thegivenname"] option:selected').val();
    
    #9374
    $("select[id=yourDropdownid] option:selected").text()
    

    This works fine

    #9384
    blankbinita-bharati
    Participant

    This works for me:

    $('#yourdropdownid').find('option:selected').text();
    

    jQuery version: 1.9.1

    #9377
    blankfaa
    Participant

    For those who are using SharePoint lists and don’t want to use the long generated id, this will work:

    var e = $('select[title="IntenalFieldName"] option:selected').text();
    
    #9375
    blanknikhil-agrawal
    Participant
     $("#selectID option:selected").text();
    

    Instead of #selectID you can use any jQuery selector, like .selectClass using class.

    As mentioned in the documentation here.

    The :selected selector works for <option> elements. It does not work for checkboxes or radio inputs; use :checked for them.

    .text() As per the documentation here.

    Get the combined text contents of each element in the set of matched elements, including their descendants.

    So you can take text from any HTML element using the .text() method.

    Refer the documentation for a deeper explanation.

    #9379
    blankAnonymous
    Inactive
    $("#dropdownID").change(function(){
      alert($('option:selected', $(this)).text());
    });
    
    #9366
    blankkishore
    Participant

    Use:

    ('#yourdropdownid').find(':selected').text();
    
    #9380
    blankmd-shahidul-islam
    Participant

    Various ways

    1. $("#myselect option:selected").text();
    
    2. $("#myselect :selected").text();
    
    3. $("#myselect").children(":selected").text();
    
    4. $("#myselect").find(":selected").text();
    
    #9363
    blankvineet
    Participant

    In sibling case

    <a class="uibutton confirm addClient" href="javascript:void(0);">ADD Client</a>
    <input type="text" placeholder="Enter client name" style="margin: 5px;float: right" class="clientsearch large" />
    <select class="mychzn-select clientList">
      <option value="">Select Client name....</option>
      <option value="1">abc</option>
    </select>
    
    
     /*jQuery*/
     $(this).siblings('select').children(':selected').text()
    
    #9368
    blanknikul
    Participant
    $('#id').find('option:selected').text();
    
    #9381

    Use this

    const select = document.getElementById("yourSelectId");
    
    const selectedIndex = select.selectedIndex;
    const selectedValue = select.value;
    const selectedText = select.options[selectedIndex].text;   
    

    Then you get your selected value and text inside selectedValue and selectedText.

Viewing 15 posts - 1 through 15 (of 31 total)
  • You must be logged in to reply to this topic.