Days
Hours
Minutes
Seconds

Super Black Friday Sale!

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

    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
    blankabctest483
    Member
    $("option:selected", $("#TipoRecorde")).text()
    
    #9383
    blankabctest483
    Member

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

    #9382
    blankabctest483
    Member

    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
    blankabctest483
    Member
    $("select[id=yourDropdownid] option:selected").text()
    

    This works fine

    #9384
    blankabctest483
    Member

    This works for me:

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

    jQuery version: 1.9.1

    #9377
    blankabctest483
    Member

    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
    blankabctest483
    Member
     $("#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
    blankabctest483
    Member

    Use:

    ('#yourdropdownid').find(':selected').text();
    
    #9380
    blankabctest483
    Member

    Various ways

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

    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
    blankabctest483
    Member
    $('#id').find('option:selected').text();
    
    #9381
    blankabctest483
    Member

    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.