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
Girish Reddy 52Girish Reddy 52 

onclick button not working, I'm not sire what is the problem. Please check the below code.

Aura Component 
<aura:component >
    <lightning:card title="Emp Details">
            <lightning:button label="Submit" onClick="{!c.Submit}"/>
    </lightning:card>
</aura:component>

Controller
({
    Submit : function(component, event, helper) {
        alert('Show Alert');
    }
})

when I click on submit button it's not working at all, I tried writing another sample code but faced the same issue. Please help
Best Answer chosen by Girish Reddy 52
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Girish,

I tried with the below code and it is working as expected.

Component:
<aura:component implements="force:appHostable"> 
    <lightning:card title="Emp Details">
     <lightning:button label="Base" title="Base action" onclick="{! c.handleClick }"/>  
    </lightning:card>
</aura:component>

Controller:
 
({
    handleClick : function(component, event, helper ) {
        alert("Show Alert");
        console.log('into console');
    }
})

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Girish,

I tried with the below code and it is working as expected.

Component:
<aura:component implements="force:appHostable"> 
    <lightning:card title="Emp Details">
     <lightning:button label="Base" title="Base action" onclick="{! c.handleClick }"/>  
    </lightning:card>
</aura:component>

Controller:
 
({
    handleClick : function(component, event, helper ) {
        alert("Show Alert");
        console.log('into console');
    }
})

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
Girish Reddy 52Girish Reddy 52
Hi Sai Praveen,

I still did not get it, What was the mistake in my code can you please say me. Also I tried your code it is also not working for me 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Girish,

How did you test this. Did you add this component as a tab? 

Thanks
 
Girish Reddy 52Girish Reddy 52
I'm trying in the salesforce Developer console on chrome browser.
While being on a component tab I clicked on the controller and from there adding the onclick function.
Girish Reddy 52Girish Reddy 52
I got the issue I was using onClick C as the capital when tried using a small letter got the output. 
Thank you Sai Praveen for your help