title: HTML form with single text field + preventing postback in Internet Explorer
body: <p>I have noticed a rather strange behaviour in IE.</p>
  <p>I have a HTML form with a single input text field and a submit button</p>
  <p>On Submit click I need to execute a client side JavaScript function that does the necessary.</p>
  <p>Now when I want to prevent the postback in the text field (on enter key press).</p>
  <p>I have added a key press JavaScript function that looks like this:</p>
  <pre><code>&lt;input type=text onkeypress=&quot;return OnEnterKeyPress(event)&quot; /&gt;
  
   function OnEnterKeyPress(event) {
              var keyNum = 0;
              if (window.event) // IE
              {
                  keyNum = event.keyCode;
              }
              else if (event.which) // Netscape/Firefox/Opera
              {
                  keyNum = event.which;
              }
              else return true;  
              if (keyNum == 13) // Enter Key pressed, then start search, else do nothing.
              {
                  OnButtonClick();
                  return false;
              }
              else
                  return true;
          }
  </code></pre>
  <p>Strangly this doesn't work.</p>
  <hr />
  <p>But if I pass the text field to the function :</p>
  <pre><code>&lt;input type=text onkeypress=&quot;return OnEnterKeyPress(this,event);&quot; /&gt;
  
   function OnEnterKeyPress(thisForm,event) {
              var keyNum = 0;
              if (window.event) // IE
              {
                  keyNum = event.keyCode;
              }
              else if (event.which) // Netscape/Firefox/Opera
              {
                  keyNum = event.which;
              }
              else return true;  
              if (keyNum == 13) // Enter Key pressed, then start search, else do nothing.
              {
                  OnButtonClick();
                  return false;
              }
              else
                  return true;
          }
  </code></pre>
  <p>I am able to prevent the postback.</p>
  <p>Can anyone confirm what is exactly happening here?</p>
  <p>The HTML form has just one text box and a submit button.</p>
  <p>The resultant output of the JavaScript function executed on submit is displayed in a HTML text area in a separate div.</p>