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 :(

1 Answer 1


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.

You must log in to answer this question.

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