Submitting a form in an iframe with JavaScript
Submit the Iframe's URL from javascript
if (window.parent.$("#IframeId").length > 0) {
window.parent.$("#IframeId")[0].contentDocument.forms[0].submit();
}
Try this:
var MyIFrame = document.getElementById("myframe");
var MyIFrameDoc = (MyIFrame.contentWindow || MyIFrame.contentDocument);
if (MyIFrameDoc.document) MyIFrameDoc = MyIFrameDoc.document;
MyIFrameDoc.getElementById("myform").submit();
UPDATE
I can't figure out why this doesn't work, but here is something that does:
MyIFrameDoc.getElementById("mybutton").click();
iframe.php:
<input type="submit" name="submit" value="submit" id="mybutton" />
UPDATE 2
The reason you're getting the submit is not a function
error is because you've named your submit button submit
, so MyIFrameDoc.getElementById("myform").submit
actually references an HTMLInputElement
, not the HTMLFormElement.submit()
method.
All you need to do is rename your submit button, e.g.:
<input type="submit" name="submit2" value="submit" />