title: Run jQuery AJAX when hitting 'enter / return'
body: <p>I have a simple form for users to post on a 'wall'. As you can see it has one text input field and a submit button that is made of multiple spans styled via CSS.</p>
  
  <pre><code>&lt;form action="http://example.com/2/chat_share" method="post" id="chat_form"&gt;                    
  &lt;input type="text" name="chat_msg" value="" /&gt;                  
  &lt;/form&gt;
  
  &lt;span class="share_js fc-button fc-button-prev fc-state-default fc-corner-left fc-corner-right"&gt;
      &lt;span class="fc-button-inner"&gt;
          &lt;span class="fc-button-content save_button"&gt;Share&lt;/span&gt;
          &lt;span class="fc-button-effect"&gt;
              &lt;span&gt;&lt;/span&gt;
          &lt;/span&gt;
      &lt;/span&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>This works nicely when the user clicks on the 'Share' button, which runs the AJAX below:</p>
  
  <pre><code>$(document).ready(function() {
  
      $('.share_js').click(function(event){
          event.preventDefault();
  
          var link = $('#chat_form').attr('action');
  
          $.ajax({
              url: link,
              type: "POST",
              data: $('#chat_form').serialize(),
              dataType: "html",
              beforeSend: function(){
                    $('#loading').show();
                  },          
              success: function() {
                  $('#chat_thread').load(2 + '/chat_ajax');
                  $('#loading').hide();
                  $('#chat_form input').val('');
              }
          });
      });
  
  });
  </code></pre>
  
  <p>My problem is that when I hit 'return' or 'enter' on the keyboard, the form is submitted via the non-AJAX method.</p>
  
  <p>I wanted to capture this keystroke using </p>
  
  <pre><code>$('#selector').keydown(function (e){
      if(e.keyCode == 13){
          //code
      }
  })
  </code></pre>
  
  <p>but haven't been able to wrap this around my AJAX function.</p>
  
  <p><strong>Ideally both clicking on Share and hitting return should submit the form.</strong></p>
  
  <p>Anyone have suggestions how to do this?</p>
  
  <p>Thanks for helping!</p>