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

Passing javascript values to the controller
Hello guys,
I need your help.
I am using some API to get the exchange rates using javascript and I am successful in that.
Now, I want these rates should be passed to the Save method defined in the controller.
To clarify, my JS function is :
function newnee(){ dollar1 = fx.convert(1, {from: 'USD', to: 'EUR'}); }
As you can see, I have set the value of dollar1. Here is my save in VF :
<apex:commandButton action="{!NewSave}" value="Save" onclick="newnee();"/>
Here is the Save in my controller :
public Pagereference NewSave() { //.......Some code and then insert ......// insert objInv ; PageReference acctPage = new ApexPages.StandardController(objInv).view(); acctPage.setRedirect(true); return acctPage; }
I have tried Actionfunction as well as inputhidden. But seems I am missing something.
What would be the best way to pass the values to the Save function(Custom)?
Can someone help me?
Thanks,
Rocky
http://boards.developerforce.com/t5/General-Development/Reg-passing-value-from-javascript-function-to-apex-controller/td-p/255259
There are 2 options:
1. Use javascript remoting, call JS function(remote action call is made within it) from commandbutton onclick event. Dont use call controller action as it would be taken care with remoting.
2. apex:actionFunction, From button's onclick event call js function to perform calculation of exchange rate. Then pass the value to apex:actionfunction and use apex:param for pasing parameter to controller method.
apex:actionFunction is simpler to use, but remoting is much faster.
Thanks a lot Rahul.
But, let me explain my scenario a little more.
I have to pass the variable value onclick of save. How do I couple apex:actionfunction in this case?
When I tried using action function with a different function other than Save, the page was executed TWO times. One - The actionfunction got executed and Two - The save executed (There were two debug instances).
Can you please correct my code for javascript remoting as well as for actionfunction? I will really appreciate this. I have truncated lot of code it between for your readability.
Controller :
Page :