
submiting a form inside an iframe from outside the iframe
This one has me stumped (friday afternoon and I am done!). I am certain it should be done (as long as the iframe content is from the same site). Yet EVERY example I have found online doesn't work in Firefox (not sure about other browsers). I have tried many possible variations. I have other workarounds, but for various reasons I would really like to be able to just have a submit button outside the iframe, that when pressed submits the content of a form inside of the iframe.
Here is just one:
window.frames['myframe'].document.forms['suggestForm'].submit();
Ultimately I get an error saying that there is no submit function, or no properties, etc.
Has anyone done this and can share their code?

NAVIGATION
HomeAbout Me
RSS
Search
Subscribe
Recent Entries
Inception Plot QuestionsRandom Chuck Norris Fact Generator With A Twist
Virtual Currency for Buses
Applying ColdFusion Security Patches Gotcha
Privacy, Walled Gardens, Standards and Our Future
Recent Comments
FireFox 3.6 KTML Editor Fix
rock guitar said: Is the ktml realy discontinued for dreamweaver
[More]
FireFox 3.6 KTML Editor Fix
Joshua said: Hi Wayne,
I just tried opening the editor in IE from the link you supplied. I was able to open the ...
[More]
FireFox 3.6 KTML Editor Fix
wayne said: Hi everybody, thanks for your reply joshua. I still have a bug for ktml in asp for a link properties...
[More]
Inception Plot Questions
said:
[More]
Inception Plot Questions
Taylor said: Hey there Josh,
Great questions all. You seem to think this is more of a Jacob's Ladder equivalent ...
[More]
Calendar
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Archives By Subject
blogs (31) [RSS]books (4) [RSS]
Crazy (39) [RSS]
DIY (8) [RSS]
Flex (3) [RSS]
games (10) [RSS]
GRRR (13) [RSS]
Ideas (11) [RSS]
Local (14) [RSS]
LOLpics (2) [RSS]
money (9) [RSS]
music (3) [RSS]
Personal (27) [RSS]
Photos (8) [RSS]
Politics (8) [RSS]
Projects (22) [RSS]
Review (19) [RSS]
RPM (9) [RSS]
Spam (16) [RSS]
Technology (68) [RSS]
Testing (3) [RSS]
TV (15) [RSS]
video (32) [RSS]
Web Dev (224) [RSS]
World of Warcraft (16) [RSS]

<script type="text/javascript">
/**
*
* SubmitForm function definition:
* Reference the iFrame: var yourVariable = parent.document.getElementById("iFrameNameHere");
* Reference to the window object generated by the the iframe: var yourWindowVariable = yourVariable.contentWindow; //other browsers use contentDocument
* Reference to the form object inside of the iFrame: var theFormObject = yourWindowVariable.document.getElementById("formNameHere");
* Submit the form now :) theFormObject.submit();
*/
function SubmitForm(){
//make a reference to the iFrame;
var iframeElem = parent.document.getElementById("iFrame");
//make a reference to the window of the iFrame (Note: for Mozilla it's diferent you got to use contentDocument instead of contentWindow);
var win = iframeElem.contentWindow;
//make a reference to the form element in the iframe;
var theForm = win.document.getElementById("form1");
//submit the form
theForm.submit();
//just testing
alert("ok");
}
</script>
and this one goes into the end just before closing the body tag:
<script>
/*
*
* Make it available in the DOM
* Reference your submit button
*
*/
var myButton = parent.document.getElementById("submit");
/**
*
* Older method of attaching event:
* myButton.onclick = SubmitForm;
*
*/
/**
*
* IE Hack - attachEvent instead of addEventListener for other browsers
*
*/
myButton.attachEvent('onclick', SubmitForm);
</script>
i've comented the javascript nothing two hard but i hope you understand it
Thanks very much for posting this. Afraid I am still having the same error, in both IE and FF. I tried it in my own code, but also just used your code on a test page. To be clear, my submit button is on the parent frame, not in the iframe. For whatever reason I just can't get at the properties of the iframe form to submit. I get either an object expected error or a iframeElem has no properties error. Pitty.
Try this:
var iframe = window.frames[<FRAMEID>].document.forms[0].submit();
You have to remember though, the contents of your iframe need to be fully loaded for this to work.
That type of error “there is no submit function, or no properties, etc.” can happen when you have an input or button with the name “submit”—change the name to something other than “submit”.