+ Start a Discussion

How can we Pass Javascript variable value to apex controller

Hi Guys,

I need you guys help!. I have javascript variable value X, I need to pass this value to apex controller method. how can we do that....

You can use the apex:param to pass the variable in apex controller

        <apex:actionfunction name="setMyParam" rerender="dummy">
              <apex:param name="test" value="" assignto="{!test}"/>



public class Demo
         public String test   {   get;set;   }

Here we are calling method  setMyParam from javascript by passing the parameter.. that will call my action function and assign the parameter value to test variable of my class

I did try the above code and it didnt work for some reason, the system.debug isnt getting the any values from VF page. I need to pass Javascript variable Value "A" to controller and get that value back to java script when I call apex method from visual force page....