- This topic is empty.
- AuthorPosts
-
October 29, 2009 at 12:02 pm #9355
abctest483MemberHow can I get the selected text (not the selected value) from a drop-down list in jQuery?
October 7, 2010 at 10:09 am #9378
zarniParticipantvar 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.
August 16, 2011 at 5:56 am #9385
abctest483Member$("option:selected", $("#TipoRecorde")).text()November 14, 2011 at 9:22 am #9383
abctest483Member$("#DropDownID").val()will give the selected index value.January 24, 2013 at 11:22 am #9382
abctest483MemberFor 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();April 23, 2013 at 10:04 am #9374
abctest483Member$("select[id=yourDropdownid] option:selected").text()This works fine
September 25, 2013 at 7:36 am #9384
abctest483MemberNovember 5, 2013 at 9:38 am #9377
abctest483MemberFor 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();January 30, 2014 at 2:29 am #9375
abctest483Member$("#selectID option:selected").text();Instead of
#selectIDyou can use any jQuery selector, like.selectClassusing class.As mentioned in the documentation here.
The :selected selector works for <option> elements. It does not work for checkboxes or radio inputs; use
:checkedfor 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.
February 1, 2014 at 5:55 am #9379
AnonymousInactive$("#dropdownID").change(function(){ alert($('option:selected', $(this)).text()); });July 31, 2014 at 3:11 am #9366
abctest483MemberUse:
('#yourdropdownid').find(':selected').text();August 3, 2014 at 7:39 am #9380
abctest483MemberVarious ways
1. $("#myselect option:selected").text(); 2. $("#myselect :selected").text(); 3. $("#myselect").children(":selected").text(); 4. $("#myselect").find(":selected").text();December 5, 2014 at 6:33 am #9363
abctest483MemberIn 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()April 11, 2015 at 9:39 am #9368
abctest483Member$('#id').find('option:selected').text();May 14, 2015 at 2:21 am #9381
abctest483MemberUse 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
selectedValueandselectedText. - AuthorPosts
- You must be logged in to reply to this topic.