title: Pressing the enter key with multiple submit buttons
body: <p>I have a single form with multiple submit buttons that are then handled using the $_POST information. The default behaviour when pressing enter is of course for the first button on the page to be "clicked" however I would like the button that is clicked to depend on where the user is in the form at the time they click it. A stripped back excerpt of php code is shown below. Note that I have tried using onkeydown/onkeypress/onkeyupp and using the event keycode (where it equals 13) to then document.getElementById("buttonName").click() but this doesn't seem to work- the first button on the form is still the one clicked.</p>
  
  <pre><code>if (isset($_POST['submit'])) {
      // move to next page
  }
  
  if (isset($_POST['add'])) {
     // add item to this page
  }
  
  $html .= '&lt;input type="text" class="text" name="submitInfo" id="submitInfo"&gt;'; // if enter is clicked while in this textbox, the submit button should be clicked
  
  $html .= '&lt;input type="text" class="text" name="OptionalAddInfo" id="OptionalAddInfo"&gt;'; // if enter is clicked while in this textbox, the add button should be clicked
  
  $html .= '&lt;input type="submit" class="button" name="add" id="add" value="Add" onClick="return addItem();"&gt;';
  
  $html .= '&lt;input class="button" type="submit" name="submit" id="submit" value="Submit" onClick="return submitForm();"&gt;';
  
  echo $html;
  </code></pre>