Find your content:

Search form

You are here

Calling a Apex controller method using JavaScript in VF page


Hi can anybody guide me how to call a method in controller from a VF page.

Attribution to: AnuRaj

Possible Suggestion/Solution #1

Apex method:

public PageReference getMyMethod(){
    return null;

Visualforce page action function:

<apex:actionFunction action="{!MyMethod}" name="myFunction" />

actionFunction works like a javascript function, so you can call it from anywhere at your page like this:

<apex:inputField value="{!something}" onchange="myFunction()" />

Attribution to: Sergej Utko

Possible Suggestion/Solution #2

There are two methods to do this :

1)Use @Remote Action Call to call the method

2)Use ACtion Function and call on the event

Here are the documentations for the same

Video of demo sessions

Summary :Use actionfunction if you need to maintain state between postbacks, remoteaction for stateless invocations

Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content