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
vamsi krishna 106vamsi krishna 106 

Is it ok to call the action and onclick event on command button at a time in visualforce..?

hey guys please help..this..
<apex:commandbutton action="{!page2}" onclick="return conrimnew(event)" value="confirm"/>

but here i need to open one confirm box..if it is ok then i need to execute the apex method .please help me guys..for first time it's working good..but  at first time if i cancel and then for next time if i ok..i am not able to call the apex method..please help me.guys..
Thanks 

VamsiKrishna


 
Best Answer chosen by vamsi krishna 106
Antonio ManenteAntonio Manente
In this situation I'd use an <apex:actionFunction>.. For example:
 
//Your command button
<apex:commandButton onclick='confirmThis(event)'/>

//use this to invoke your apex method
<apex:actionFunction name='callMethod' action='{!page2}'/>


//javascript
function confirmThis(event){
  if(confirm(WHATEVER_YOU_WANT_TO_CONFIRM)){
    callMethod();
  }
}

Hope this helps!