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}

  • 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 '17 at 3:57
  • 2
    What if you add aura:id to the select – Eric Apr 5 '17 at 4:11
3

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>   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.