title: How to trigger hidden JSF commandLink in JavaScript?
body: <p>I have a similar question on this <a href="https://stackoverflow.com/questions/13206421/why-click-event-working-fine-in-firefox-but-not-ie">thread</a> where I have a JavaScript function which will trigger the click event of a hidden <code>commandLink</code>. And the hidden command will fire the action in Java Bean. This code is working fine in IE, but not in Firefox. Is there any clue on this issue?</p>
  
  <p><strong>JavaScript</strong></p>
  
  <pre><code>&lt;h:outputScript target="head"&gt;
      HTMLElement.prototype.click = function() {
      var evt = this.ownerDocument.createEvent('MouseEvents');
      evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
      this.dispatchEvent(evt);
    }
  
    function triggerHiddenEvent() {
      alert("triggerHiddenEvent is trigger");
      document.getElementById("theForm:hiddenCommand").click();
    }
  &lt;/h:outputScript&gt;
  </code></pre>
  
  <p><strong>XHTML</strong></p>
  
  <pre><code>&lt;h:form id="theForm"&gt;
    &lt;h:commandLink id="tri_HiddenEvent" value="Trigger Hidden Event" onclick="triggerHiddenEvent"/&gt;
  
    &lt;p style="display:none"&gt;
      &lt;h:commandLink id="hiddenCommand" styleClass="button" action="#{helloBean.doHiddenCommand}"/&gt;
    &lt;/p&gt;
    ...
  </code></pre>
  
  <p><strong>The Bean</strong></p>
  
  <pre><code>@ManagedBean
  @SessionScoped
  public class HelloBean implements Serializable {
    public String doHiddenCommand() {
      System.out.println("doHiddenCommand is called");
      return "";
    }
  }
  </code></pre>