1

I am having two functions one is java script function named as Capturing Signature() and anther one apex class function named as savePDF(). I am trying to call this two methods on button's onClick method in VF Page. For this so far i have tried this.

**This code calling only one method "SavePDF()"**
      <input id="saveSigButton" type="button" name="SigCap" onclick="CaptureSignature();savePDF();" value="Submit"/ >

*This code calling only one method "CaptureSignature()"**

      <input id="saveSigButton" type="button" name="SigCap" onclick="CaptureSignature(),savePDF()" value="Submit"/ >

Kindly help to resolve this.Thanks in advance

4 Answers 4

4

To call apex class (controller) function named savePDF(), use apex:commandButton component with action attribute binding set to {!savePDF}, calling the savePDF() method of the underlying controller:

<apex:commandButton action="{!savePDF}" value="Save" id="theButton" />


To call JS function named CaptureSignature() on click of the button, use apex:commandButton with onclick attribute set to CaptureSignature();:

<apex:commandButton onclick="CaptureSignature();" value="Save" id="theButton" />


To call both, the controller method as well as the JS function, use apex:commandButton with both action and onclick attributes set:

<apex:commandButton action="{!savePDF}" onclick="CaptureSignature();" value="Save" id="theButton"  />
2

you can user to call Apex function in VF page. for example:

<apex:actionFunction name="savePDF" action="{!savePDF}" rerender="out" status="myStatus"/>

<apex:commandButton action="{!save}" value="Save" id="theButton" onclick="savePDF(),CaptureSignature()"/>

for more reference

Java script functions you can invoke normally.

1
  • thanks for reply i tried this function but savepdf only run Jan 23, 2014 at 8:34
1

You can use apex function with java-script to implement this :

<apex:actionFunction name="savePDFApex" action="{!savePDF}" />

<script type="text/javascript">
function CaptureSignature() {
/*
do what you want to do.
*/
savePDFApex();
}

</>

<apex:commandButton value="Save" id="theButton" onclick="CaptureSignature()"/>
2
  • thanks for reply i tried this function but savepdf only run Jan 23, 2014 at 8:33
  • @Lavanya Sanathkumar I have updated the code. I have removed action attribute from commandButton. You can try this now. It should work.
    – S.Sharma
    Jan 25, 2014 at 1:50
0
<apex:actionFunction name="savePDF" action="{!savePDF}" rerender="out" status="myStatus"/>

<apex:commandButton action="{!save}" value="Save" id="theButton" onclick="savePDF()"/>

use ActionFunction for calling two methods on single command button click. onclick event runs the ActionFunction and the second method will be called

1
  • <apex:actionFunction name="savePDF" action="{!savePDF}" rerender="out" status="myStatus"/> <apex:commandButton action="{!save}" value="Save" id="theButton" onclick="savePDF()"/>
    – satishh
    May 8, 2017 at 6:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .