title: Specifying default a4j:commandButton when press Enter in JSF form
body: <p>My <strong>JSF form</strong> contain<br>
  <strong>Multiple</strong> <code>h:inputText</code> and <strong>Multiple</strong> <code>a4j:commandButton</code><br>
  Also<br>
  I have 2 buttons (search) and (reset)  </p>
  
  <p>My need when i <code>press Enter</code> during editing any <code>h:inputText</code><br>
  (search) button will be fired  </p>
  
  <pre><code>&lt;h:form id="searchForm" onkeypress="formKeypress();"&gt;
  
      &lt;h:panelGrid columns="4" &gt;
  
          &lt;h:outputText value="name" /&gt;
          &lt;h:panelGroup&gt;
              &lt;h:inputText 
                  title="name"
                  value="#{myController.name}" &gt;                          
              &lt;/h:inputText&gt;
              &lt;a4j:commandButton 
                  title="name Detail"
                  action="#{myController.nameDetail}" &gt;               
              &lt;/a4j:commandButton&gt;
          &lt;/h:panelGroup&gt;
  
          &lt;h:outputText value="city" /&gt;
          &lt;h:panelGroup&gt;
              &lt;h:inputText 
                  title="city"
                  value="#{myController.city}" &gt;                          
              &lt;/h:inputText&gt;
              &lt;a4j:commandButton 
                  title="name Detail"
                  action="#{myController.cityDetail}" &gt;               
              &lt;/a4j:commandButton&gt;
          &lt;/h:panelGroup&gt;
  
      &lt;/h:panelGrid&gt;
  
  
      &lt;h:panelGrid &gt;
          &lt;h:panelGroup&gt;
              &lt;a4j:commandButton
                  id="searchButton" 
                  value="search" title="search"
                  action="#{myController.search}"
                  render="searchResultsGrid" /&gt;                       
          &lt;/h:panelGroup&gt;
      &lt;/h:panelGrid&gt;
  
  
      &lt;f:verbatim&gt;
          &lt;script type="text/javascript" &gt;
              &lt;!--
  
              function formKeypress() {
              //  if (event.keyCode == 13) {
              //      document.getElementById('searchForm:searchButton').click();
              //      return false; 
              //  }
              }
  
              --&gt;
          &lt;/script&gt;
      &lt;/f:verbatim&gt;       
  
  &lt;/h:form&gt;
  </code></pre>
  
  <p>the problem is that
  when i <code>press Enter</code> during editing any <code>h:inputText</code>
  the first <code>a4j:commandButton</code> in the form will be fired
  Not the (search) button</p>
  
  <p>Note<br>
  I checked the answer<br>
  <a href="https://stackoverflow.com/q/5485851/1824361">Default action to execute when pressing enter in a form</a><br>
  But that for <code>h:commandButton</code><br>
  And I face JavaScript error exception  </p>
  
  <p><code>ReferenceError: event is not defined<br>
  [Break On This Error]<br>
  if (event.keyCode == 13) {</code> </p>