1 Reply Latest reply on Jul 4, 2012 1:53 AM by Tong Li

    Need help here...With h:inputHidden

    Tong Li Newbie

      Actually what I wanted to do is passing a javascript value to an entity bean. so I got this.

      <h:form class="myForm">
                    <p id="test">Please enter your name:sadfas</p><br/>
                    <h:inputText value="#{annotation.content}" /><br/>
                    <h:inputHidden id="hidden" value="#{annotation.time}"/>
                    <a4j:commandButton value="save" onclick="setTime()" action="#{annotationManager.addIn(annotation)}" reRender="annotationTable"/>
      </h:form>
      

      and with a javascript function

      <script type="text/javascript">
                    function setTime()
                          {
                                    var time = Math.round($f().getTime());          // this is the time I want to pass to the entity bean
                                    document.getElementById('myForm:hidden').value = time;          // problem occurs here
                                    document.getElementById("test").innerHTML = time;               // I use this to test whether the function is actually performed
                          }
      </script>
      

      With above code, when I click on the commandButton in the page, nothing happened at all, but if I delete this line

       

      document.getElementById('myForm:hidden').value = time;          // problem occurs here
      

       

      The programe works. It change the value of <p id="test">, which means it performed the javascript function.

       

      I am not sure if this is the correct way to do this, but I have searched for the solution for few hours and none of them helped.

       

      I think the problem is that program can't get the value from the hidden field through "document.getElementById('myForm:hidden').value"

       

      Thank you in advance.

        • 1. Re: Need help here...With h:inputHidden
          Tong Li Newbie

          Wow. Never thought I could find the solution this so fast after I post this thread.

          I replace document.getElementById('myForm:hidden').value = time;

          with document.getElementById('myForm:hidden').setAttribute("value", time);

          and it works.

          By the way, I also change <h:form class="myForm"> to <h:form id="myForm">.

          Dont know how it affects.