i am getting undefined when i try to pass attribute value (from button which opens a modal) to Java script function.


 <button type="button" data-id="test" onclick="{!c.DetailPage}" class="btn btn-warning btn-lg pull-right" data-toggle="modal" data-target="#myModal">Click</button>


JS Controller:

 DetailPage : function(component, event, helper) {
// tried multilple scenarios..all returning "undefined"

After retrieving this value i need to set this value to my drop down list..

<aura:attribute name="options" type="String[]"/>

<button type="button" data-id="{!v.options}"    ...../>
<ui:inputSelect aura:id="ProductPlatform" class="form-control" label="Product Platform" change="{!c.onSelectChange}" required="true"> 
    <aura:iteration items="{!v.pltfrmGrpOptions}" var="level" indexVar="index">
        <aura:if isTrue="{!index ==0}">
        <ui:inputSelectOption value="true" label="{!level}" text="{!level}"/>
        <aura:set attribute="else">
        <ui:inputSelectOption label="{!level}" text="{!level}" />

you can get current button attributes from event object using following way

  • Question Edited. This helps. But i need to set this data-id value to my drop down list. on the first attempts alert(event.target.getAttribute("data-id")) returns null, on second it gives correct value. – Anchal Jindal Nov 26 '15 at 9:49
  • i can use component.set() to set the value ...Coming to (event.target.getAttribute("data-id") but it returns null on first click.. Second click it gives value... but do not set the Drop down. – Anchal Jindal Nov 27 '15 at 6:09

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.