0

I have a script where I have two value. a and b.

   <script>
      var a= 1; 
      var b=2; 
   </script>

I want to pass this value to my controller which have a method.

 public class mycontroller {

     public void myvalues(string a1, string b1){
         system.debug(a1 + ' '+ b1);
     }

 }

Haw can I achieve this. Please help me with the best way to get the solution.

1 Answer 1

1

Use an apex:actionFunction paired with apex:param. https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

VF Page:

<script>
  var a = 1;
  var b = 2;
  doWork(a, b);
</script>

<apex:actionFunction action="{!mywork}" name="doWork" rerender="something">
  <apex:param name="firstParam" assignTo="{!aVar}" value="" />
  <apex:param name="firstParam" assignTo="{!bVar}" value="" />
</apex:actionFunction>

Controller:

public class MyController
{
  public String aVar{get; set;}
  public String bVar{get; set;}

  public PageReference myWork()
  {
    //aVar and bVar should both already be assigned here
    System.debug('avar = ' + aVar);
    return null;
  }
}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.