function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Newbie_edmNewbie_edm 

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....
sslodhi87sslodhi87

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

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


<script>
setMyParam('setmyvalue');
</script>


</apex:page>

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
 

Newbie_edmNewbie_edm
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....

thanks