Sample:
Visualforce page:
<apex:page sidebar=”false” Controller=”Sample” showHeader=”true”>
<apex:form >
<apex:commandButton value=”show” onClick=”return confirmReq();” action=”{!show}”/>
</apex:form>
<apex:outputPanel id=”jspanel”>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js” type=”text/javascript”></script>
<script>
function confirmReq() {
if(condition) {
return true;
} else {
{
return false;
}
</script>
</apex:outputPanel>
</apex:page>
Controller:
public class Sample {
public sample() {
}
public void show() {
/*……………….
……………….
……………….
……………….*/
}
}
in the above example, show() from Apex will not be executed until the Javascript function returns true.
Cheers!!!