2

I have two function which needs to be called from one button. Currently I am doing this by creating two button one "Confirm" and another "Save". but I don't want two button I want only one button "Save", on click of Save first the method called by "Confirm" button should be called and then the method called by "Save" button.

Below is my code:

<apex:commandButton value="Confirm" action="{!save}"/>   
<apex:commandButton value="Save" action="javascript:top.window.opener.closeFunction()" ></apex:commandbutton> 

3 Answers 3

1
<apex:commandButton value="Save" action= "{!save}"
  Oncomplete="javascript:top.window.opener.closeFunction()" />

Instead of onclick try - oncomplete event.

0
0

You can bind the javascript call to onclick and then the apex call using action on the same button..

something like

<apex:commandButton value="Save" action= "{!save}"
  onclick="javascript:top.window.opener.closeFunction()" />
2
  • I tried this one but it's not working Commented Jul 12, 2015 at 18:23
  • u can different options.. try using oncomplete event if required.. or try moving the javascript code into a separate function.. Commented Jul 12, 2015 at 23:30
0

Another option: you can use javascript Remoting. First, you call the save action with javascript remoting. Then, in the callback, you call your second javascript method. This way, you are ceratin that the second function (the javascript function) fires after your apex function.

Here is an example of Javascript remoting: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm

You must log in to answer this question.

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