Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmitting a form in an iframe with JavaScript
    text
    copied!<p>The <code>iframe</code> is on the same domain, I tried the following code, but none of it worked:</p> <pre><code> myframe.document.getElementById("myform").submit(); parent.top.frames[0].document.forms[0].submit(); myframe.document.getElementById("myform").submit(); MyIFrame = document.getElementById("myframe"); myIFrame.getElementById("myform").submit(); </code></pre> <p>Update:</p> <p>This is the HTML:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;iframe frameborder="0" scrolling="no" width="530" height="298" src="/iframe.php" name="myframe" id="myframe"&gt; &lt;p&gt;iframes are not supported by your browser.&lt;/p&gt; &lt;/iframe&gt;&lt;br /&gt; &lt;form action="/styles.css" method="post" id="form1"&gt; &lt;input type="text" name="input1" value=""/&gt; &lt;input type="text" name="input2" value=""/&gt; &lt;input type="button" value="test" onclick="submitFrame()"&gt; &lt;input type="submit" value="submit"&gt; &lt;/form&gt; &lt;script&gt; function submitFrame(){ var MyIFrame = document.getElementById("myframe"); var MyIFrameDoc = (MyIFrame.contentWindow || MyIFrame.contentDocument); if (MyIFrameDoc.document) MyIFrameDoc = MyIFrameDoc.document; MyIFrameDoc.getElementById("myform").submit(); // ## error } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>iframe.php:</p> <pre><code>&lt;form method="post" class="af-form-wrapper" id="myform" name="myform" action="/" &gt; &lt;input type="text" name="input1" value="2073809442" /&gt; &lt;input type="text" name="input2" value="1" /&gt; &lt;input type="submit" name="submit" value="submit" /&gt; &lt;/form&gt; </code></pre> <p>Firebug says:</p> <pre><code> MyIFrameDoc.getElementById("myform").submit is not a function </code></pre>
 

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