- This topic is empty.
-
AuthorPosts
-
October 29, 2009 at 12:02 pm #9355haddarParticipant
How can I get the selected text (not the selected value) from a drop-down list in jQuery?
October 7, 2010 at 10:09 am #9378zarniParticipantvar 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 #9385rafaelParticipant$("option:selected", $("#TipoRecorde")).text()
November 14, 2011 at 9:22 am #9383neerajParticipant$("#DropDownID").val()
will give the selected index value.January 24, 2013 at 11:22 am #9382kamrulParticipantFor 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 #9374thangamani–palanisamyParticipant$("select[id=yourDropdownid] option:selected").text()
This works fine
September 25, 2013 at 7:36 am #9384binita-bharatiParticipantNovember 5, 2013 at 9:38 am #9377faaParticipantFor 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 #9375nikhil-agrawalParticipant$("#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.
February 1, 2014 at 5:55 am #9379124Participant$("#dropdownID").change(function(){ alert($('option:selected', $(this)).text()); });
July 31, 2014 at 3:11 am #9366kishoreParticipantUse:
('#yourdropdownid').find(':selected').text();
August 3, 2014 at 7:39 am #9380md-shahidul-islamParticipantVarious 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 #9363vineetParticipantIn 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 #9368nikulParticipant$('#id').find('option:selected').text();
May 14, 2015 at 2:21 am #9381mohammed-shaheen-mkParticipantUse 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
andselectedText
. -
AuthorPosts
- You must be logged in to reply to this topic.