• Bharta Chand
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Guys,

I am trying to pass Javascript Variable value to apex method, it always returns null in apex method when i try to see the value using system.debug,  I did try the following solution from net but still not working, any thoughts?

thanks,

--------------------------------------------------------------------------------------------------------------------------------------------

public class myController {
  public string myProperty {get; set;}
 

  public void myTest() {
    System.debug('VARIABLE MYPROPERTY------' + myProperty);

  }

}
 
And on the visualforce you can pass javascript variable as -
 
Using InputHidden
<apex:inputHidden value="{!myProperty}" id="inptHdn"/>
 
<script>
  function passVariable() {
    String str = 'my test value';
    document.getElementById('<ID OF INPUT HIDDEN>').value = str;
  }
</script>
 
Using action function
 
<apex:actionFunction name="myFun" action="{!myTest}">
  <apex:param name="a" value="" assignTo="{!myProperty}"/>
</apex:actionFunction>
 
and you can call this action function from javascript method as
 
<script>
  function passVariable() {
    String str = 'my test value';
    myFun(str);
  }
</script>

-----------------------------------------------------------------------------------