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
krishna casukhela 7krishna casukhela 7 

How to pass inputHiddenfield value to apex controller

Hello
I have like this in my visualforce page
<apex:page controller="somename">

<apex:form>
<apex:inputHiddenField value="{!firstname}" id="hiddenfield">
<apex:inputText value="{!firstName}" id="fname" onchange="GetFirstName(this);"  />

<apex:commandButton value="Save" action="{!SaveChanges}"/>
</apex:form>
<script type="text/javascript">
  function GetFirstName(data)
  {
      var hiddenvalue=document.getElementByID('data').value;
      alert(hiddenfield);  // am getting the correct value in alert
 }
</script>
</apex:page>
Now what I require is to have value of javascript variable(hiddenvalue) in my apex controller.
I want to do some action when I click the button so inside button code I need to have the value of javascript variable.
I hope I am clear.
without using action function or apex:param is there a way to do this?

pls let me know, urgent.

thanks
krishna
Vickal GuptaVickal Gupta
Try below code:
 
<apex:inputHidden value="{!fName}" styleClass="inputHidden" onChange="yourMethod();" />

<script>
    var hVal = j$('.inputHidden').val();
    alert('The inputHidden value = '+hVal.toString());

    //Your logic.......

</script>
Hope this will help.
 
krishna casukhela 7krishna casukhela 7
Hi
can u pls clarify, should it be on change of inputText?
also how do I get the value into my controller.?
Thanks
Krishna