1

I want to get the text from the selected picklist option

<select name="selectItem" aura:id="selectList"  label="Select an item" onchange="{!c.handleChange}">
        <option >choose one...</option>
        <option  value="92">Pkr</option>
        <option value="33">FSD</option>
       <option value="12">DAW</option>
    </select>

I know by using component.find("selectList").get("v.value"); its return 92 ,0r 33 or 12 but i want to get pkr or FSD or DAW . I want to display that text which is selected in picklist. Hope you all understand the question.

8
  • 1
    ok. Want me to edit the question title?
    – user91246
    Commented Jul 7, 2021 at 12:53
  • It would be great if you can edit the title. much appreciated =)
    – glls
    Commented Jul 7, 2021 at 12:53
  • okay. no problem
    – user91246
    Commented Jul 7, 2021 at 12:55
  • did you try getting the elements innerHTML ?
    – glls
    Commented Jul 7, 2021 at 12:57
  • i don't get it?
    – user91246
    Commented Jul 7, 2021 at 12:59

1 Answer 1

0

You should be able to get it using below type snippet:

<aura:component>
<lightning:select name="selectItem" aura:id="selectList"  label="Select an item" onchange="{!c.doSomething}">
   <option >choose one...</option>
    <option  id="92">Pkr</option>
    <option id="33">FSD</option>
   <option id="12">DAW</option>
</lightning:select>
</aura:component>

JS controller:

({
handleChange: function (cmp, event, helper) {
    //Press button to change the selected option
    cmp.find("selectList").get("v.value");
    console.log(cmp.find("selectList").get("v.value"));
  }
})

The output looks as below: enter image description here

3
  • cmp.find("selectList").get("v.value"); As I explain its give me value not a text
    – user91246
    Commented Jul 7, 2021 at 13:36
  • @Fawadazam, Did you try running the code and checked the browser console, if it brings you text selected or the id provided to options? Commented Jul 7, 2021 at 13:47
  • Ok.got it but what if i have values like <option text="{!option.label}" value="{!option.value}" selected="{!option.selected}"/> ???
    – user91246
    Commented Jul 7, 2021 at 14:24

You must log in to answer this question.