Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get the fireEvent method to work in IE8?
    primarykey
    data
    text
    <p>I'm trying to submit a form using IEs fireEvent method. Here's some simple test code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function fireSubmit () { if (document.createEventObject) { var event = document.createEventObject (); var fired = document.forms['fireForm'].fireEvent("onsubmit", event); alert("event fired: " + fired + "; event returnValue: " + event.returnValue); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button onmouseover="fireSubmit();"&gt; Hover to submit &lt;/button&gt; &lt;form name="fireForm" action="action.html" method="post"&gt; &lt;input type="submit" name="submit" value="submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here's the simple action.html that should get submitted:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script&gt;alert('submitted');&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If I hover over the button, the event does get created and IE claims it was fired. An alert pops up that says "event fired: true; event returnValue: <strong>undefined</strong>", but the action.html alert is never shown and the returnValue is never set contrary to what <a href="http://msdn.microsoft.com/en-us/library/ms536423(v=vs.85).aspx" rel="nofollow">this</a> claims. However, if I just click on the submit button, the form is actually submitted and the "submitted" dialog shows. </p> <p>What am I doing wrong? Am I misusing IE in some heinous way?</p> <p><em><strong>edit</em></strong>: Basically I'm trying to use the event model to catch problems down the line. The following code using <a href="https://developer.mozilla.org/en/DOM/element.dispatchEvent" rel="nofollow">dispatchEvent</a> works fine in non-IE browsers for the same purpose:</p> <pre><code> if (document.createEvent) { var event = document.createEvent("HTMLEvents"); event.initEvent("submit", false, false); var returnValue = document.forms['fireForm'].dispatchEvent(event); alert("event returnValue: " + returnValue); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload