title: javascript, limit number of characters in text field
body: <p>I have a form which allows only for numbers to be entered in the text box, or an alert appears:</p>
  
  <pre><code>&lt;form name="formName" action="" method="post" OnSubmit="return chkSubmit();"&gt; 
      Input Number 
      &lt;input type="text" name="txtNumber" value=""&gt;
      &lt;input type="submit" name="btnSubmit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>with the following javascript:</p>
  
  <pre><code>&lt;script&gt;
  function chkSubmit()
  {
       if(isNaN(document.formName.txtNumber.value))
       {
          alert('Please input numbers only.');
          return false;
       }
  }&lt;/script&gt;
  </code></pre>
  
  <p>How do I allow for only 4 characters to be entered?  No alert, just prevent the user from typing more than 4 characters.</p>