You need to sign in to do that
Don't have an account?
Dream_weaver
How to call a controller method from javascript that will return a value not null..
Can we use----var x={!method} ?? in javascript...not working for me..
Using <action function >we can access controller method but the method is 'pagereferece' type so it will return null...I want to return a value from controller method to javascript.....How to do?
You have several options:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm
you can also assign directly like you say "var x = {!methodA};" or "var x = '{!methodA}'; " (within quotes).
(take into account that you should have a method in apex called 'getMethodA' )
you can even reRender part of your code with javascript involved to reassign variables.
Hope this help. Regards
All Answers
You have several options:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm
you can also assign directly like you say "var x = {!methodA};" or "var x = '{!methodA}'; " (within quotes).
(take into account that you should have a method in apex called 'getMethodA' )
you can even reRender part of your code with javascript involved to reassign variables.
Hope this help. Regards
You can use Actionfunction for calling method in cotroller -
suppose -
<apex: page>
<apex:form id ="frm">
<apex:actionfunction name="callfromJS" action="{!controllerMethodName} reRender="frm"/>
</apex:form>
<script>
function JSmethodCallFromAnyAction()
{
callfromJS();
}
</apex:page>
This JS method you call from any action like onclick, onchange etc. This method call actionfunction(actionfunction: used for calling controller method without submitting the page) . reRender is used for refresh particular protion.
Thank you.
Please marked as solution for benefits of others persons.
var x = '{!methodA}'; " (within quotes)---It worked..Thanks a lot..