You need to sign in to do that
Don't have an account?

actionfunction - passing multiple variables to JS function oncomplete
I must be doing something very simply stupid.
I have two JS Functions, one takes a single variable and a second JS function that takes two variables.
All of these variables are in my Apex Controller and updated based on user input. I can't just call the variable directly in the function because it only get's set on the page load and not when a user makes an update.
For my first JS function with only 1 varilable I call using an ActionFunction that calls the PageReference to update the variable in the Controller and then calls my JS Function oncomplete and passes the variable to the JS Function.
Like this:
<apex:actionFunction name="DurationCalculate" action="{!CalDuration}" rerender="Rec_Rev_Term,PanelTesting" oncomplete="setARRT({!duration})" > </apex:actionFunction> <script type="text/javascript"> function setARRT(duration) { var months = duration; //set ARRT data document.getElementById('{!$Component.page.ProductForm.ContractProductsBlock.pbs.pbsiARRT.OutputARRT_m}').innerHTML = months; } </script>
This works perfectly!
So I tried doing this with my function that takes two variables. The actionfunction gets called but the actual JS function isn't.
<apex:actionFunction name="CalPriceType" rerender="PanelTesting" oncomplete="setPrices({!duration},{!Price_Type})" > </apex:actionFunction> <script type="text/javascript"> function setPrices(duration,PriceType) { if(PriceType == 'Recurring') { .... do this } return false; } </script>
What am I doing wrong? Both {! duration } and {! Price_Type} can change base on the user input. The values are set correctly in the controller.
Hi,
Here is an example parameter passing with actionFunction and JS
<apex:param id"bname" name="fname" value="" />
</apex:actionFunction> /*Call the javaScript from here*/ <apex:commandLink onclick="doSave('{!$Component.interviewDate}','{!$Component.fname}');"> <apex:commandButton value="Save"/> </apex:commandLink> /*get the parameter in controller IN saveInterviewDate method */ String interviewdate=Apexpages.currentPage().getParameters().get('interviewDate');
String name=Apexpages.currentPage().getParameters().get('name');
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
All Answers
Have you tried placing alerts inside the setPrices method to ensure that it is not being called?
such as:
Also, your actionFunction is not inside the area being rerendered right?
Looks like price_type is not a number. So enclose it inside single quote or double quote. Please note that a quote mark inside same type of quote mark has to be escaped.
"setPrices({!duration},'{!Price_Type}')"
Hi,
Here is an example parameter passing with actionFunction and JS
<apex:param id"bname" name="fname" value="" />
</apex:actionFunction> /*Call the javaScript from here*/ <apex:commandLink onclick="doSave('{!$Component.interviewDate}','{!$Component.fname}');"> <apex:commandButton value="Save"/> </apex:commandLink> /*get the parameter in controller IN saveInterviewDate method */ String interviewdate=Apexpages.currentPage().getParameters().get('interviewDate');
String name=Apexpages.currentPage().getParameters().get('name');
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Thanks!
Turns out I was missing the single quotes when passing the controller variables to Javascript.
It is odd that if I pass 1 variable I don't need the single quotes and need them when passing multiples.
It's working now which is what's important. Great example! That's much clearer than the "MethodOne" example I found in documentation!
It is not about number of parameters. It is about whether it is a number, boolean or string value.