Apex:commandButton and onClick issue...

Friday, October 2, 2009 by Aslam - The Alexendra
Hi,
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:-

<script>
function confirm(){
if(something condition){
return true;
}
return false;
}
</script>

<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........


Thanks
Posted in | 6 Comments »