+ Start a Discussion
shiv@SFDCshiv@SFDC 

How to call standard save method using java script button on standard page.

Hi All,

As we know in custom VF page following code woks perfectly and calls the stndard save method. if JS function return true. else it will not call standard save method.
<apex:commandButtion action{! Save} onclick="return validate()" />

<script>
    function validate()
    {
        if(true){
            return true ;
        }
        else{
            return false;
        }
    }
</script>

Can we acheive the same thing using standard JS button on standard VF Page ? If yes. Please provide some code sample.
Thanks.
SarfarajSarfaraj
You have to use actionfunction,
<apex:actionFunction action="{!Save}" name="saveFn"/>
    <apex:commandButton action="{!Save}" onclick="return validate()" value="Save"/>
    <input type="button" value="Save" onclick="if(validate()) saveFn();"/>
    <script>
    function validate()
    {
        if(true){
            return true ;
        }
        else{
            return false;
        }
    }
    </script>
--Akram
shiv@SFDCshiv@SFDC
Functionality is working fine for me. My question is that can we do it using standard java script button.
SarfarajSarfaraj
Seems like I misunderstood your requirement. Can you please elaborate with an example how you are going to create this javascript button? I will try to help you on calling the Save action from there.