function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MRITYUNJAY PATEL 3MRITYUNJAY PATEL 3 

How to get the Account Name in Controller.js

Hello there,
Please solve my problem, first time i am trying to ask question .

this is my component code:
<select aura:id="AccList" class="slds-select" >
            <option>All</option>
            <aura:iteration items="{!v.Accounts}" var="category" indexVar="index" >
                <option>{!category.Name}</option>
            </aura:iteration>
        </select>

Controller.js
    var selectedValue=  component.find("AccList").get("v.Value");
    alert("selectedValue:"+selectedValue);

Advance Thanks
   
Best Answer chosen by MRITYUNJAY PATEL 3
Suraj Tripathi 47Suraj Tripathi 47

Hi,

Please find the solution.

You are not able to get the values in selectedValue variable because js is case sensitive 

wrong:      var selectedValue=  component.find("AccList").get("v.Value");

correct:     var selectedValue=  component.find("AccList").get("v.value");

you can try other way also

component:

<div >
        <lightning:select name="select1" class="slds-select" label="ACCOUNTS" required="false" onchange="{!c.OpportunityfromAccount}"  >
           <option>All</option>
            <aura:iteration items="{!v.Accounts}" var="ac" >
                <option value="{!ac.Id}" label="{!ac.Name}" />
            </aura:iteration>
            
        </lightning:select>
        
    </div>

controller:

OpportunityfromAccount:function(c,e,h){
        var selectedValue=e.getSource().get("v.value");
            alert("selectedValue:"+selectedValue);
    },

Please let me know it is working or not?

Please mark it as the Best Answer so that other people would take reference from it.

Thank You

All Answers

ShivankurShivankur (Salesforce Developers) 
Hi Mrityunjay,

Try modifying your code in following manner:
<aura:component>
<aura:attribute name="Accounts" type="Object[]"/>

<aura:handler name="change" value="{!v.Accounts}" action="{!c.doInit}"/>

<div class="slds-form-element__control">
    <div class="slds-select_container">
        <select id="categoryPicklist" class="slds-select">
            <option>All</option>
            <aura:iteration items="{!v.Accounts}" var="category" indexVar="index">
                <option>{!category.Name}</option>
            </aura:iteration>
        </select>
    </div>
</div>

</aura:component>

And in the JS file you can access it in following way:
component.find("categoryPicklist").get("v.value");

Refer to similar example here on below thread for more clarity:
https://salesforce.stackexchange.com/questions/106015/lightning-how-do-i-get-the-selected-value-from-a-select-dropdown-list-send-i

Hope above information helps. Please mark as Best Answer so that it can help others in future.

​​​​​​​Thanks.
Suraj Tripathi 47Suraj Tripathi 47

Hi,

Please find the solution.

You are not able to get the values in selectedValue variable because js is case sensitive 

wrong:      var selectedValue=  component.find("AccList").get("v.Value");

correct:     var selectedValue=  component.find("AccList").get("v.value");

you can try other way also

component:

<div >
        <lightning:select name="select1" class="slds-select" label="ACCOUNTS" required="false" onchange="{!c.OpportunityfromAccount}"  >
           <option>All</option>
            <aura:iteration items="{!v.Accounts}" var="ac" >
                <option value="{!ac.Id}" label="{!ac.Name}" />
            </aura:iteration>
            
        </lightning:select>
        
    </div>

controller:

OpportunityfromAccount:function(c,e,h){
        var selectedValue=e.getSource().get("v.value");
            alert("selectedValue:"+selectedValue);
    },

Please let me know it is working or not?

Please mark it as the Best Answer so that other people would take reference from it.

Thank You

This was selected as the best answer
mukesh guptamukesh gupta
Hi Patel 

Please use below code:-
 
<aura:attribute name="Accounts" type="Object[]"/>
<lightning:select name="cStat" label="Account List" aura:id="accPicklist" 
 onchange="{!c.onChange}">
 <aura:iteration items="{!v.Accounts}" var="opt">
  <option value="{!opt.Name}">{!opt.Name}</option>
 </aura:iteration>
</lightning:select>

controller.js:-
 
onChange: function (cmp, event, helper) {
 var selPickListValue = event.getSource().get("v.value");
        console.log('******selPickListValue :'+selPickListValue );
}

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh