Ken B
Ken B

Reputation: 99

How to retrieve the selected text in 'change'

I am looking to retrieve the text of the currently selected object.
When I do a $(this).text() I get all of the available selections

I have tried the following without the desired result:

$(this).text()

$(this).selected()

$(this).selected().text()
$('#simpSR_CodeSet_' + id).off().on('click', function (e) {
            app.requireInput('simpSRDet_Units_' + id, false);
            app.requireInput('simpSRDet_Visits_' + id, false);
            app.requireInput('simpSRDet_Frequency_' + id, false);

            let _text = this.selected.text();

            alert(_text);

            $('#simpSRDet_Units_' + id).val('');
            $('#simpSRDet_Visits_' + id).val(1);
            $('#simpSRDet_Frequency_' + id).val(1);

            $('.srsimplediv_unit_visits_' + id).show();

        });

<script id="srsimple_ServiceTemplate" type="text/x-handlebars-template">
                        <ul class="srsimpledetail">
                            {{#services}}
                                <div id="srsimple_service_{{id}}" class="srsimpleService form">
                                    <fieldset>
                                        <dl>
                                            <dt>Service Type:</dt>
                                            <dd>
                                                <select id="simpSR_SvcServiceRequestTypeId_{{id}}"></select></dd>
                                        </dl>
                                        <dl>
                                            <dt>Code Set:</dt>
                                            <dd>
                                                <select id="simpSR_CodeSet_{{id}}" class="InputDD" /></dd>
                                        </dl>

I just want the text of the currently selected item in the list, not all the available items. I need to show/hide fields based on what the text is displaying.

Upvotes: 1

Views: 71

Answers (2)

Ken B
Ken B

Reputation: 99

Thanks Aakash. I was able to use a slight modification of what you posted.

$(this).children("option").filter(":selected").text()

Upvotes: 0

Aakash Martand
Aakash Martand

Reputation: 944

Try this

$("#dropDownId").children("option").filter(":selected").text()

Upvotes: 2

Related Questions