Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

How to pass jquery value result into visualforce code for example:

My jquery code is:

$j('[id$=submit]').on("click", function(){

 var output = [], $jselects = $j(".container .row .span6 #form-details select"), i;

 for (i=0; i < $jselects.length; i += 2)

    output.push($jselects.eq(i).find("option:selected").text() +

                ":" + $jselects.eq(i+1).find("option:selected").text());

})

When I click this id, the output values are generated like b:b,s:s,a:a This values are stored into a variable as output

Here is my visualforce code:

<apex:commandButton id="submit" action="{!myMethod}" value="Submit" styleClass="btn btn-primary" reRender="block">

  <apex:param name="myParam" value="output"/>

</apex:commandButton>

When I press the id submit, get the output value from jquery and it will be set in the place of outputin <apex:param name="myParam" value="output"/> this line. Here the output text is generated, but I need to know how to send that value inside this <apex> code.

Is it possible or not...?

Appreciate for your answer...

1 Answer

0 votes
by (32.1k points)
edited by

Use the RemoteAction like this: 

In JavaScript:

Visualforce.remoting.Manager.invokeAction(

   '{!$RemoteAction.yourController.yourfunction}',your_data,

           function(result, event){

              //the result of your apex code

           }

);

In Apex:

@RemoteAction

public static string yourfunction(String your_data) {

    // do your stuff

    return result;

}

Want to get certified in Salesforce? Here is the Salesforce Online Training you are looking for.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers

501 comments

104k users

Browse Categories

...