Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I have two command buttons cancel, canceAll. I have two methods cancel, cancelAll in conteoller. How can i call actionfunctions from single javascript function based on the button clicked? I tried like this but it is not saving, showing compilation error.

function cancelAllFunc(Clicked_Id){
            var id = Clicked_Id.id;
            if (confirm("--?") == true) {
                if(id='1') {
                    cancelAllMethod();
                }
                else {
                    cancelMethod();
                }
            } else {

            }
          }

<apex:commandButton value="Cancel All" onclick="cancelAllFunc()" id="1"/>
<apex:commandButton value="Cancel" onclick="cancelAllFunc()" id="2"/>

<apex:actionFunction name="cancelAllMethod" action="{!cancelAllMethod}" />
<apex:actionFunction name="cancelMethod" action="{!cancelMethod}" />
share|improve this question

marked as duplicate by sfdcfox, martin, Ratan, Mohith Shrivastava, Sergey Utko Apr 11 '16 at 5:57

This question was marked as an exact duplicate of an existing question.

    
@martin, my scenario is different from that. Here i have two button, two different methods. But these methods called in single js function based on button clicked. – Vijay Kumar Apr 11 '16 at 5:12

I think the main problem you were having was that you were using <apex:commandButton>s, since that tag calls actions defined in the page controller, rather than javascript functions on the page.

<input type="button" value="Cancel All" onClick="cancelAllFunc(this.id);" id="1"/>
<input type="button" value="Cancel" onClick="cancelAllFunc(this.id);" id="2"/>

<script>
function cancelAllFunc(Clicked_Id){
    var id = Clicked_Id.id;
    if (confirm("--?") == true) {
        if(id='1') {
            cancelAllMethod();
        }
        else if(id='2') {
            cancelMethod();
        }
    }

}
</script>

<apex:actionFunction name="cancelAllMethod" action="{!cancelAllMethod}" />
<apex:actionFunction name="cancelMethod" action="{!cancelMethod}" />
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.