title: onpage load call commandbutton in JSF
body: <p>I'm trying to set value to hidden variable on page load and call  to send that value to managedbean.Onpage load i'm able to set value and call commandbutton and get value in managed bean but its going to unconditional loop and executing more than once. Here's my code.</p>
  
  <pre><code>&lt;script&gt;
  window.onload = setId ;
  
  function setId(){
  var facId = document.getElementById('formname:bId').value;
  document.getElementById('formname:nameId').value = facId;
  document.getElementById('formname:buttonId').click();
  }
  &lt;/script&gt;
  
  &lt;h:inputText id="nameId" value="#{bean.nameId}"&gt;&lt;/h:inputText&gt;
  &lt;h:commandButton id="buttonId" value="fId" action="#{bean.init()}" /&gt;
  </code></pre>
  
  <p>On page load its calling the button contineously.</p>