function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

apex:actionFunction not working

 I need to use the actionFunction tag to perform validation first in JS and then launch a controller method.

The controller method returns a new page reference.


However it seems my controller method is not called...


VF: ( I did not include validation yet as first I want the method call working)


<apex:page controller="HelloWorld">

<apex:form >

<apex:actionFunction name="myChange" action="{!change}" rerender=""/>
<apex:commandButton value="Warning" onclick="javascript&colon;confirmation();"/>


function confirmation() {



Apex method:



   public PageReference change(){
      PageReference pageRef = new PageReference('/apex/HelloWorld');
      return pageRef;







I suspect its because of the rerender attribute - that tells VF to apply the changes to the existing page.  Remove that and the page should refresh correctly.


I have actually had another solution in another post (I was trying to have a pop-up asking if the user really wants to continue):


So I used the "return confirm" statement in the onclick attribute, which worked very well on my test page.


However I am wondering if it is because I have added an apex:param inside the button:


<apex:commandButton value="Mark As Complete" onclick="return confirm('test');" action="{!markPillarAsComplete}" reRender="Merchant_Introduction_Engagement_Section">
                        <apex:param name="pillarName_MarkAsComplete" value="Merchant Intro Engagement" assignTo="{!pillarName_MarkAsComplete}" />


When I click on my button I do get a confirmation pop-up, however the Apex action is not executed....



I would expect your action method to execute, but as you have specified the rerender attribute you won't be able to redirect to a different page. 


When I remove "rerender"  the warning and action work well.

But now I have a dilemma:


Basically I have a section that show some records  and my "Complete" button.

When clicking on that button, the action method marks all these actions as Complete and returns a PageRefefernce so that a full page refresh is done. The problem is that the updated actions do no display if I don't rerender the appropriate section (which I never understood since it is a full page refresh, hence a rerender should not be needed).


Now the business asks for a warning pop-up before proceeding, which I can implement thanks to your solution (using onclick="return confirm..."


But now I need to find a solutiuon where I can use onclick and rerender at the same time...


Do you have any ideas?