I am calling controller function on command button click.

This is button:

<apex:commandButton value="Add" onClick="addItemToCard('{!$Component.bVAL}', '{!item.Id}'); return false;"/>

This is actionFunction:

<apex:actionFunction name="addToCardFunction" action="{!addToCard}" reRender="items"> 
    <apex:param name="count" value="" assignTo="{!itemCount}"/> 
    <apex:param name="id" value="" assignTo="{!itemId}"/> 

I call controller function in js:

function addItemToCard(itemCountId, id) { 
    addToCardFunction(document.getElementById(itemCountId).value, id); 

I don't know why, but my addToCard() controller method is called only in the first time . When I click button second time, nothing happens. Page is just reloaded :(


I think it might be to do with your use of an apex:commandButton. Since you are just calling a Javascript function, just use a regular button like so:

<button onclick="addItemToCard('{!$Component.bVAL}', '{!item.Id}'); return false;">Add</button>

Normally with a commandButton you would call an action method directly - not doing that could cause issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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