+ Start a Discussion
TryCodingTryCoding 

How to Set controller variable from javascript

 

Can we set the value of controller variable in JavaScript using binding {! }; something same as we  retrieve it by writing

alert(‘{!myVariable}’);

 

Ritesh AswaneyRitesh Aswaney

You can use apex:actionFunction (though it has been superceded by Javascript remoting more recently)


have a look at this

 

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

 

In a line, an actionFunction has a call to a controller method, and can be invoked by a javascript function, which is invoked on an event. You can also pass parameters to the controller using apex:param

 

TryCodingTryCoding

 

By action function i will call controller method and this will set value of variable.

 

My question is we can retrieve  controller variable values in javascript by just binding it like {! variable}

 

Can we also set the value of this variable   from javascript something like {!variable} = value

 

Sothat i do not have extra overhead of an action function and a method in controller just to set the value.

 

Thanks