Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- How to call a controller method from javascript th...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How to call a controller method from javascript that will return a value not null..
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-29-2012 04:48 AM
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?
Solved! Go to Solution.
Re: How to call a controller method from javascript that will return a value not null..
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-29-2012 08:53 AM
You have several options:
http://www.salesforce.com/us/developer/docs/pages/
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
If this post solves your problem/issue/question, please mark it as solution.
SFDC Certified Developer
Re: How to call a controller method from javascript that will return a value not null..
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-29-2012 10:04 AM
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.
Re: How to call a controller method from javascript that will return a value not null..
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-30-2012 10:20 PM
var x = '{!methodA}'; " (within quotes)---It worked..Thanks a lot..

