title: Defining a default button when pushing enter key
body: <p>I have a Grails app which contains a <code>.gsp</code> page with a number of <code>textField</code>s, several <code>submitToRemote</code> buttons, and a couple <code>actionSubmit</code> buttons on it. When filling out the <code>textField</code>s, I want to be able to hit enter after I'm done, and have it do the same as clicking a specific <code>submitToRemote</code> button.  Currently it is acting as if I clicked a specific <code>actionSubmit</code> button that I never intentionally specified. </p>
  
  <p>I found this: <a href="https://stackoverflow.com/questions/12955222/how-to-trigger-html-button-when-you-press-enter-in-textbox">How to trigger HTML button when you press Enter in textbox?</a> .  It seems like what I want, so I adapted it to my page, but it doesn't appear to be doing anything.  </p>
  
  <p>I'll forgo posting the entire <code>.gsp</code> but add what I feel is appropriate for the question.</p>
  
  <p>Here is the button that is being activated currently:</p>
  
  <pre><code>&lt;br&gt;
      &lt;g:hiddenField name="type" value="head"/&gt;
      &lt;g:actionSubmit value="Get Reports" action="showReports"/&gt;
  &lt;br&gt;
  </code></pre>
  
  <p>Here is the button that I <b>want</b> to be activated:</p>
  
  <pre><code>&lt;g:submitToRemote value="find" url="[action: 'findCustomer']"
  update="results" /&gt;
  </code></pre>
  
  <p>So what I did was add an id to both the target <code>submitToRemote</code> button, and 1 <code>textField</code>, then added the <code>&lt;g:javascript&gt;</code> tag wrapping around the scrip from the above linked page.  Which looks like this:</p>
  
  <pre><code>&lt;g:textField name="lastName" id="inputTextBox"/&gt;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;g:submitToRemote value="find" id="findCustomer" url="[action: 'findCustomer']"
  update="results" /&gt;
  </code></pre>
  
  <p>... </p>
  
  <pre><code>&lt;g:javascript&gt;
   $(document).ready(function(){
     $('#inputTextBox').keypress(function(e){
       if(e.keyCode==13)
       $('#findCustomer').click();
    });
  });
  &lt;/g:javascript&gt;
  </code></pre>
  
  <p>Also, I am using the jQuery library as such:</p>
  
  <pre><code>&lt;g:javascript library="jquery" /&gt;
  </code></pre>
  
  <p>I'm not sure if my approach here is flawed, as I do need it to work on any of the 10 <code>textField</code>s on the page.  I went through the grails documentation and couldn't find anything that really matched this...</p>