+ Start a Discussion
kmorf_entransformkmorf_entransform 

How to use apex:actionFunction

Hi im trying to find an alternative to

<apex:page standardcontroller="Shipment" action="{!agree}">

</apex:page>

 by using apex:actionFuntion so that the code looks something like this

<apex:page standardcontroller="Shipment" >
some code...
...
<apex:actionFucntion name="agree" action="{!agree}"/>

</apex:page>

 can someone help me?

Best Answer chosen by Admin (Salesforce Developers) 
hemantgarghemantgarg

It can be called on window.onload event like :-

 

 

<apex:page >

   <apex:form>

       <apex:actionFuction name="agreeJS" action="{!agree}" /> 

</apex:form>

<script>

  window.onload = new function(){ agreeJS();}

</script>

</apex:page>

 

 

All Answers

raseshtcsraseshtcs

Action function is used to call the controller methods from javascript... This link should make things clearer

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

kmorf_entransformkmorf_entransform

is there an alternative to

<apex:page Controller="Shipment__c" action="{!agree}">

</apex:page>

 so that action="{!agree}" is not called within the apex:page component when the page is rendered. For example

<apex:page Controller="Shipment__c">
..... action="{!agree}"
</apex:page>

 apex method agree should automatically be called when the page is rendered

hemantgarghemantgarg

It can be called on window.onload event like :-

 

 

<apex:page >

   <apex:form>

       <apex:actionFuction name="agreeJS" action="{!agree}" /> 

</apex:form>

<script>

  window.onload = new function(){ agreeJS();}

</script>

</apex:page>

 

 

This was selected as the best answer
kmorf_entransformkmorf_entransform

Thanks for the help. that works perfectly

CEPCEP

what's the trick to avoid having an infinie loop when the page loads?