You need to sign in to do that
Don't have an account?
Yukinon
Get value from LWC button
I want to get the value of the clicked button but it's returning undefined when using event.getSource().get("v.cs")
Component
Component
<aura:component controller="CaseCreationController" implements="flexipage:availableForAllPageTypes" access="global"> <aura:attribute name="caseType" type="List" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <lightning:card> <div class="slds-p-around_medium"> <aura:iteration items="{!v.caseType}" var="cs"> <lightning:button variant="brand-outline" label="{!cs}" onclick="{!c.createCase}" name="{!cs}" value="{!cs}" /> </aura:iteration> </div> </lightning:card> </aura:component>JS
createCase : function (cmp, event, helper) { var btnVal = event.getSource().get("v.cs"); alert(btnVal); }
Try Below Line Please Mark It As Best Answer If It Helps
Thank You!
All Answers
Try Below Line Please Mark It As Best Answer If It Helps
Thank You!
hi Yukinon,
You need to try below code for getting data.
For Value => event.getSource().get('v.value');
For Label => event.getSource().get('v.label');
you can get any attribute value from event.getSource().get('v.attributeName');
let me know by marking it as the best answer.
Thank you