title: Prevent typing spaces in an HTML text box with jQuery
body: <p>So I've got an <code>HTML</code> form that users can type in. How can I use javascript/jQuery to immediately and seamlessly remove spaces from a text box when one is put in? I've been researching the <code>.val()</code> jQuery method and came up with this:</p>
  
  <pre><code>$('input').keydown(function() {
      str = $(this).val();
      str = str.replace(/\s/g,'');
      $(this).val(str);
  });
  </code></pre>
  
  <p>That does weird things to removing text and the spaces still show up on keystroke, they just get removed on the following keystroke. Any suggestions?</p>