Reply
Regular Contributor
Dream_weaver
Posts: 32
0
Accepted Solution

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?

 

 

 

Trusted Contributor
SeAlVa
Posts: 185
0

Re: How to call a controller method from javascript that will return a value not null..

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

 

--- Firma ---
If this post solves your problem/issue/question, please mark it as solution.

SFDC Certified Developer
Regular Contributor
Raj
Posts: 41
0

Re: How to call a controller method from javascript that will return a value not null..

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.

 

 

Regular Contributor
Dream_weaver
Posts: 32
0

Re: How to call a controller method from javascript that will return a value not null..

var x = '{!methodA}'; " (within quotes)---It worked..Thanks a lot..