(Lightning) How do I get the selected value from a Select dropdown list & send it to a method?

I’m trying to implement a single option select dropdown list for my component, and I’ve gotten as far as displaying the data members and the correct values for them. However, I can’t find any example within the SLDS website that gives me an idea of how to get this value out. I’m still new to working with Lightning(and front-end in general).

Here’s the code I’ve written:

<aura:component>
<aura:attribute name="productCategories" type="Object[]"/>

<aura:handler name="change" value="{!v.productCategories}" action="{!c.doInit}"/>

<div class="slds-form-element__control">
    <div class="slds-select_container">
        <select id="categoryPicklist" class="slds-select">
            <option>All</option>
            <aura:iteration items="{!v.productCategories}" var="category" indexVar="index">
                <option>{!category.label}</option>
            </aura:iteration>
        </select>
    </div>
</div>

</aura:component>

How would I get the chosen option data and pass it into my controller?

Answer

In your javascript controller, you can get the component using the find method and then get the attribute value of the comonent using the get method..

component.find("categoryPicklist").get("v.value");

Refer this Trailhead module for more details

Attribution
Source : Link , Question Author : wwchiang , Answer Author : Vamsi Krishna Gosu

Leave a Comment