Can any one tell me how to call JavaScript function from jquery.


                  $('.email2Class').bind("cut copy paste",function(e) 
callJavascript();//call javascriot from here


Basically I am validating a visualforce form through Jquery and after validations I am trying to call a controller method, as there is no way to call a controller method from Jquery as far as I know. So, I want to invoke JavaScript method which in turn will invoke the controller method.

Note: Above code is just a sample one.



jQuery is JavaScript. Just call the function normally. You can call an actionFunction, RemoteAction, and so on.

As a trivial example, here's a simple incremental controller. Every time you call increment, the value increases by 1:

public class counterController {
    public Integer counter { get; set; }
    public counterController() {
        counter = 0;
    public void increment() {

In the page, I'll use jQuery to bind to the keypress event, which in turn will call the controller's "increment" function:

<apex:page controller="counterController">
    $(function() {
        $(window).on("keypress", function() {
            alert("I'm about to increment the counter.");
    <apex:form id="form">
        Press a key to increment the counter.
        <apex:actionFunction name="incrementCounter" action="{!increment}" reRender="form" />
        The counter is now {!counter}.
  • Cab you please elobrate? Aug 7 '16 at 20:31
  • I tried calling it normally it is not working and my method should be called on after validation successful from jquery Aug 7 '16 at 20:34
  • @PraveenBiyani I've included a trivial example that demonstrates how it could work. You might want to include a specific example of what's not working so we have something to troubleshoot.
    – sfdcfox
    Aug 7 '16 at 20:48
  • I have tried the same thing but my controller method is not calling it. Aug 8 '16 at 17:23
  • Hi @sfdcfox When ever actionFunction is getting called the browser is getting refreshed and my controller method is also not called. Any help on this? Aug 8 '16 at 19:28

You can use this type of code with JavaScript Remoting for Apex Controllers


<script type="text/javascript">
 var j$ = jQuery.noConflict(); 
enter j$(document).ready(function(){
      MyController.updateMethod("ABC", function(result, event){



public class MyController{
public list <MyObject__c> pub {get;set;}
public MyController(ApexPages.StandardController controller) {

public static void updateMethod(MyObject__c myObj)
    //do some update

    update myObj;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.