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
devendra dhakadevendra dhaka 

action function behaviour

I am using action function as a function to load on the pageLOAD.

 

If i use a normal javascript function, it's working fine.

 

but with this actionFunction, 'm getting a blank page.

 

Correct me :)

 

 

<apex:form >
    <apex:actionFunction name="currentMonthLoad" reRender="Caption1">
    
    alert("was here once");
    </apex:actionFunction>
    </apex:form>

 

 

    function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
     window.onload = func;
  }
  else
  {
      window.onload = function()
      {
        if (oldonload)
        {
           oldonload();
        }
        func();
      }
   }
}
   
addLoadEvent(function()     
{
 
   currentMonthLoad();
  
});

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Calling that function doesn't help - the {!leaveDays} appeared in the page when it was rendered, so unless you rerender that section of javascript before you call it, the value will be the same as when the page was rendered.

All Answers

bob_buzzardbob_buzzard

Have you checked to see if you have any javascript errors on the page?  I'm not sure what will be made of the alert in the body of the actionfunction tag.

devendra dhakadevendra dhaka

I don't know what exactly happened , but it stareted working. I had to remove the alert .

 

 

I used the actionfunction to pass value from javascript to controller.

 

but when I used the action as a pagereference function, it gave me null value of the passed variable.

 

So I created a new function and checked the values. Now they are correct

 

What can be the reason for this ??

bob_buzzardbob_buzzard

I've found that you have to specify a rerender attribute to get the parameter passed through to the controller.  Was this something that you changed to get it working?

devendra dhakadevendra dhaka

I already had the rerender in the actionFunction.

It was present in both the cases. So shoud I remove it ??

 

 

One more thing.

 

I am creating an list in the controller and then in the vf Page 'm using

 

leaveDays= '{!leaveDays}'  ;

 

to store the array in the javascript array.

 

It's working fine for the first time, but at later stage it keeps the same value, no updation ..

bob_buzzardbob_buzzard

That makes sense if you are using rerenders - unless you rerender the section that contains the javascript, and cause it to re-execute, the value will stay the same.

devendra dhakadevendra dhaka

function functionName(){  
       
       
        leaveDays= '{!leaveDays}';
      
      }

 

 

'm calling this function as a oncomplete event of the action call.

 

But this javascript array is maintaing its previous value, while it has been updated in the controller.    

bob_buzzardbob_buzzard

Calling that function doesn't help - the {!leaveDays} appeared in the page when it was rendered, so unless you rerender that section of javascript before you call it, the value will be the same as when the page was rendered.

This was selected as the best answer