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
John L.John L. 

Javascript invocation of actionFunction: Can it be done?

If I have the page

<apex:page> <apex:form> <apex:actionFunction name="fubar" action="{!myApexMethod}"> <apex:param name="firstParam" assignTo="{!myflag}" value=""/> </apex:actionFunction> </apex:form> <script type="text/javascript"> fubar('{!$Profile.Id}'); </script> </apex:page>

the getMyFlag method seems to run at "page-delivery time", rather than at client-side "page-load time". Is there anyway to change this apparent behavior?

 

I'm not interested in how it works (if it can), just how to make it work with the current implemetation.

 

Thanks in advance for any help you may provide.

Best Answer chosen by Admin (Salesforce Developers) 
John L.John L.

Mine was a sequencing problem. I was able to obtain the desired behavior by moving the <apex:form> and its contents AFTER the <script> node.

 

I was unaware that JavaScript functions could be invoked prior to the definition of the function in the containing page. (in this case anyhow)