title: How to cancel submit in IE8?
body: <p>I've been struggling to make this work for quite some time. I have the following code:</p>
  
  <pre><code>$(document).ready(function (event) {
      $('form').submit(function (event) {
      ...
      });
  });
  </code></pre>
  
  <p>I've found in most of the places, including on the jQuery site, that this will prevent the form from being submitted:</p>
  
  <pre><code>return false;
  </code></pre>
  
  <p>It doesn't.</p>
  
  <p>Next I've read all related question and answers on this site and tried them all out.
  In Chrome and Firefox this works:</p>
  
  <pre><code>event.preventDefault();
  </code></pre>
  
  <p>In IE8 it doesn't. I've read that IE doesn't support this and we should use this:</p>
  
  <pre><code>event.returnValue = false;
  </code></pre>
  
  <p>Although several people confirm that it worked for them (e.g. <a href="https://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie-any-help">event.preventDefault() function not working in IE. Any help?</a>), it doesn't for me. I'm not sure why though. I have a form with a submit button, nothing special, but, even if I put only this piece of code, the form is still submitted:</p>
  
  <pre><code>$(document).ready(function (event) {
      $('form').submit(function (event) {
          event.returnValue = false;
      });
  });
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>One last thing: I've read that we should test this first before calling preventDefault():</p>
  
  <pre><code>if (event.preventDefault) { event.preventDefault(); }
  </code></pre>
  
  <p>But in IE8, event.preventDefault exists and no error is thrown. How can that be if it's unsupported by IE?</p>
  
  <p><strong>Update 1:</strong> I've tried a simplified version with the following code:</p>
  
  <p>CancelSubmitTest.aspx:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CancelSubmitTest.aspx.cs" Inherits="HtmlEditor.CancelSubmitTest" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="Scripts/CancelSubmit.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;asp:Button ID="SaveButton" runat="server"
              Text="Save" OnClick="SaveButtonClick" CausesValidation="true" ValidationGroup="SomeValidationGroup" /&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>CancelSubmitTest.aspx.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace HtmlEditor
  {
      public partial class CancelSubmitTest : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          protected void SaveButtonClick(object sender, EventArgs e)
          {
  
          }
      }
  }
  </code></pre>
  
  <p>CancelSubmit.js</p>
  
  <pre><code>$(document).ready(function (event) {
      $('form').submit(function (event) {
          event.returnValue = false;
      });
  });
  </code></pre>
  
  <p>It's a pretty straight-forward example. The JavaScript code is executed but the form is still submitted, although I set event.returnValue to false. What am I doing wrong?</p>
  
  <p><strong>Update 2:</strong> I've changed the javascript code in the simplified project as follows:</p>
  
  <pre><code>$(document).ready(function (event) {
      $('form').submit(function (event) {
          return false;
      });
  });
  </code></pre>
  
  <p>It works in IE but I still have to figure out why it doesn't work in my application. Thanks to everyone for your help.</p>