Apex:commandButton and onClick issue...

Friday, October 2, 2009 by Aslam - The Alexendra
Sometimes we find issues when we use <apex:commandButton> with both onClick and Action. We try to return false / true from our javascript method and expect things to be happen properly but sometimes it not happens. See below:-

function confirm(){
if(something condition){
return true;
return false;

<apex:commandButton value="Submit" action="{!CallAction}" onClick="return confirm();"/>

The above code does not call action sometimes..(Dont know why)...so if you change it with this, it will work:-
<apex:commandButton value="Submit" action="{!CallAction}" onClick="if(!confirm()) return false;"/>

The above code will work....Please don't ask why........