-3

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}" />
0

1 Answer 1

0

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}" />

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