SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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
    Have a good day.

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's some information on using JavaScript to programmatically control forms: http://www.quirksmode.org/js/forms.html

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

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can access the document of an iframe:

    Code javascript:
    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:

    Quote Originally Posted by MDC
    Scripts trying to access a frame's content are subject to the same-origin policy, and cannot access most of the properties in the other window object if it was loaded from a different domain.
    https://developer.mozilla.org/en/HTML/Element/iframe

  4. #4
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys couldn't use that method, seems its cross site scripting so I had to use the GET method.
    Have a good day.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •