1

Component code:

<lightning:select name="wallheight" label="Wall Height : " onchange="{!c.doSomething}">            
    <aura:iteration items="{!v.wallheight}" var="wallheight">  
        <option text="{!wallheight.Name}" value="{!wallheight.value}" selected="{!wallheight.selected}"/>                   
    </aura:iteration>
</lightning:select>     

Controller code:

doSomething : function(component,event,helper){
    console.log(component.find("wallheight").get("v.value"));        
   //alert(x);
}  

I am getting below error

This page has an error. You might just need to refresh it. Action failed: c:form$controller$doSomething [Cannot read property 'get' of undefined] Failing descriptor: {c:form$controller$doSomething}

2
  • It seems that your JavaScript controller was not able to find the wallheight variable from component. That is the reason it throws error as cannot read something of undefined
    – sunny
    Apr 5, 2017 at 3:57
  • 2
    What if you add aura:id to the select
    – Eric
    Apr 5, 2017 at 4:11

1 Answer 1

4

You have to use aura:id instead of name.

Try this :

<lightning:select aura:id="wallheight" label="Wall Height : " onchange="{!c.doSomething}">            
    <aura:iteration items="{!v.wallheight}" var="wallheight">  
        <option text="{!wallheight.Name}" value="{!wallheight.value}" selected="{!wallheight.selected}"/>                   
    </aura:iteration>
</lightning:select>   

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .