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
theAlchemist2889theAlchemist2889 

Asynchronous Behavior Of Actionfunction creating issues.

Hi,

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. 
bob_buzzardbob_buzzard
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:

http://bobbuzzard.blogspot.co.uk/2011/05/refreshing-record-detail-from-embedded.html

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.