title: JQuery: Keyup, how do I prevent the default behavior of the arrow (up & down) and enter key?
body: <p><strong>JavaScript (JQuery)</strong></p>
  
  <pre><code>$('input').keyup(function(e)
  {
      var code = e.keyCode ? e.keyCode : e.which;
  
      switch(code)
      {
          case 38:
          break;
  
          case 40:
          break;
  
          case 13:
          break;
  
          default:
          return;
       }
   });
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form method="post" action="/"&gt;
  &lt;input type="text" name="text" /&gt;
  &lt;button type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have 2 problems:</p>
  
  <p>1) The caret shouldn't move when I hit the <strong>up</strong> arrow key.</p>
  
  <p>For example, in Chrome when I hit the up-key it moves the caret to the left. But I only have this problem in Chrome. It works fine in FF.</p>
  
  <p>2) When I hit the <strong>enter</strong> key, I don't want the form to be submitted.</p>
  
  <p>BTW, I want to get this to work with <strong>keyup</strong> and not <strong>keypress</strong>.</p>
  
  <p>I'd appreciate any ideas. Thanks.</p>