How to submit a form in an iframe with POST data?

Hi guys I am working on an application and it needs to access a third party service through an iFrame. I basically need to know how I can have Javascript autofill the fields and then submit the form that is contained in an iframe. Is this possible?

Thanks,
Darren

Here’s some information on using JavaScript to programmatically control forms: http://www.quirksmode.org/js/forms.html

In a nutshell:


document.formId.action = "http://third.party.service.com/script.php";
document.formId.inputName.value = "some value";
document.formId.submit(); // submit form

You can access the document of an iframe:

var iframedoc = document.getElementById('the_iframe').contentWindow.document;
var inputs = iframedoc.getElementsByTagName('input');
// do stuff with inputs...
iframedoc.getElementsByTagName('form')[0].submit(); // submit a form

I’ve never actually done this so I’m not sure if it’ll work - I suspect not because of this:

https://developer.mozilla.org/en/HTML/Element/iframe

Hey guys couldn’t use that method, seems its cross site scripting so I had to use the GET method.