title: Javascript preventing submit of a form after carriage return
body: <p>I'm using a barcode-scanner to add data to some html fields. What I want to do is the following</p>
  
  <ol>
  <li>focus on first field</li>
  <li>scan and enter data into the first field </li>
  <li>switch the focus to the second field</li>
  <li>scan and enter data into the second field </li>
  <li>submit form</li>
  </ol>
  
  <p>I tried two approaches:</p>
  
  <ul>
  <li>Catching the carriage return sent by the hand scanner</li>
  <li>Catching every keystroke in the textfield</li>
  </ul>
  
  <p>Posted is the latter one.</p>
  
  <p>It works sofar, but only if I leave my debug alerts in the code...
  If I remove them, the form is submitted...</p>
  
  <p>Any idea why?</p>
  
  <pre><code>    &lt;html&gt;
  &lt;head&gt;
  &lt;head&gt;
  &lt;title&gt;Webinterface&lt;/title&gt;
  &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1"&gt;
  &lt;/head&gt;
  
  &lt;script type="text/javascript"&gt;
      function processForm(e) {
      if (e.preventDefault) e.preventDefault();
      return false;
  }
  function checkFieldC(text)
  {
      if(text.length==6){
          alert("C1");
          if(document.comform.Destination.value.length&gt;0){
              alert("C2a");
              document.forms["comform"].submit();
              return true;
          }else{    
              alert("C2b");
              document.comform.Destination.focus();            
              return false;
          }
      }
      return false;
  }
  function checkFieldD(text)
  {
  
      if(text.length==9){
          if(document.comform.Container.value.length&gt;0){
              alert("D2a");
              document.forms["comform"].submit();
              return true;
          }else{    
              alert("D2b");
              document.comform.Container.focus();            
              return false;
          }
      }
      return false;
  }
  &lt;/script&gt;
  
  &lt;form method="POST" name="comform" action="DoSomething.php"&gt;
  
  &lt;br&gt;
  &lt;table width="90%"  border="0"&gt;
  
      &lt;tr&gt;
          &lt;td valign="top" width="150"&gt;Container (6 digits)&lt;/td&gt;
          &lt;td&gt;&lt;input name="comvalue[]" type="text" id="Container" size="10" maxlength="6" onkeyup="checkFieldC(this.value)" &gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;br&gt;
      &lt;tr&gt;
          &lt;td valign="top" width="150"&gt;Destination:&lt;/td&gt;
          &lt;td&gt;&lt;input name="comvalue[]" type="text" id="Destination" size="10" onkeyup="checkFieldD(this.value)"&gt;&lt;/td&gt; 
  
      &lt;/tr&gt;
  
      &lt;tr&gt;
       &lt;td&gt;Confirm&lt;/td&gt;
       &lt;td&gt;&lt;button name="s2" onClick="submit()" class="cssButton1"&gt;Confirm&lt;/button&gt;&lt;/td&gt;
      &lt;/tr&gt;    
  &lt;/table&gt;
  &lt;/font&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>