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

Asynchronous Behavior Of Actionfunction creating issues.


I have a VF page and controller. On the VF page I need to show a popup (Javascrpit confirmation box). This popoup should be shown on when a certain variable in controller is true. To achieve this I first call an actionfunction on 'Onclick' of button which updates the variable to true of false based on controller varibales. Now i call another function on onclick which checks the value of the variable updated by actionfunction. The problem here is I am not getting the updated value in my second javascript function. How to overcome/achieve this? Any help is appreciated. 
If you are calling an actionfunction you have to wait until it completes before you can take any action based on the server side processing.  There are a couple of ways to do this - if you are using rerender tags you can add an actionstatus with an onstop JavaScript handler that will be invoked once the actionfunction completes.  The other way (and one which I use quite a lot) is to conditionally render JavaScript once the actionfunction completes, and take whatever action I need to then.  

There's an example of the second option in my blog at:

This conditionally renders some JavaScript after saving a record, and this JavaScript then refreshes the entire page.  Not a matfch for you use case I know, but demonstrates the concept and should be readily adaptable.