+ Start a Discussion
abhi_sfdcabhi_sfdc 

action and onclick attributes on commandLink

Can i use action and onclick attribute on command line apex component together?

Can anyone give me some examples?

 

 

izayizay

In a case like this I use the oncomplete event and not the onclick event. Many times if I use the onclick event the action won't execute.

 

Ex.

<apex:commandLink action="{!someAction}" value="myLink" oncomplete="javascript&colon;jsFunction();"/>

Prafull G.Prafull G.
Yes. you can use.
onClick is javascript funcion and will be called before action method.

example
<apex:commandLink value="Click Me" onClick="onClickJSMethod();" action="{!controllerAction}"/>
AnushaAnusha

Of Course you can,

and you can return value from JS Function, if that value is true then system will call action of that Command Link, 

<apex:commandLink value="Click" onClick="return JSFunction();" action="{!controllerAction}"/>

vijaymindvijaymind
Its not working in my case , even my method is returns true.

Here is the code.
<apex:commandButton value="Send" action="{!sendEmail}" onclick="return checkValidation();"/>
checkValidation returning true values still action doesnot working,.
Ray GuyRay Guy
In case anyone arrives here from google, the reason the above snippet doesn't work is because the attibute is "onClick" not "onclick".