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
SS KarthickSS Karthick 

Order of Execution method in Command Button

Hi folks,
      Can anyone tell me how to execute the action mthod as first and javascript function as second .

My problem is: I have command button which has action method and js function.
I want to execute action function as first like (handle all the validation errors ) and then execute javascript function if there is no valdiation error.
If there is valdiation error then the page still remains same.

For this so far i have tried following

< apex:commandButton value="Next" styleClass="btn btn-success" action="{!tab3}" reRender="TabContent" oncomplete="changeStyle('{!$Component.tab3}','{!$Component.tab2}','{!$Component.tab1}','{!$Component.tab4}');"/>

Here am using oncomplete method but it doesnot work what I expect. Is there anyway to implement ?

Thanks in advance
Best Answer chosen by SS Karthick
You don't have the conditionality in the commandbutton component to be able to execute some JavaScript based on the results of the action method.

The way that you have to approach this is to execute the action method and set a flag to indicate if there were any validation problems.  Then you rerender some JavaScript when the action method completes which does whatever it needs to only if the flag indicates no errors occurred : 

There's an example of conditionally rendering some JavaScript based on the completion of an action method on my blog at: