Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    submitting form in iframe from main page not working right

    I have an IFrame that contains a form and a link on the main page to submit the form in the IFrame. If I use a submit button in the form in the IFrame, then the form submits properly. It does not work properly if I try to submit with JavaScript from the main page. The form in the IFrame posts back to the same page. I have supplied some code snippets below. They are not complete. Just examples to show the problem.

    You can see there is an alert to display the contents of notes_1 on the form submit within the IFrame. There is also an alert at the end of the IFrame page to show the contents of note_1 upon load. If I change the contents of notes_1 and press the submit button in the IFrame, the first alert will show me the current content of notes_1 (the changed value). Upon reloading, the alert shows the contents of notes_1 to be the original value from the db because I'm not actually saving changes yet.

    You see that all the Save link does on the main page is click the same submit button I pushed manually above. But when I do this the alert shows me the OLD value of notes_1 before I typed in something else. The alert on the bottom of the IFrame page happens showing that the page has reloaded, but IT DOESN'T REFRESH THE IFRAME. The IFrame continues to show what I typed into the field before pressing the Save link.

    Two things I do not understand: 1) Why does posting from the main page give me an alert with the old value? and 2) why does the IFrame not refresh upon the post? The post was successful but the IFrame doesn't show so.

    This is HTTPS if that makes any difference.

    Thanks,
    Kirt

    <!-- This is the main doc snippet -->
    <fieldset>
    <legend>&nbsp;Emergency Contacts&nbsp;&nbsp;<a href="#" onclick="SaveEmergencyContacts(); return false;">[Save]</a>&nbsp;</legend>
    <iframe SRC="EmergencyContacts.php" name="ECIframe" id="ECIframe" width="622" height="210" frameborder="0"></iframe>
    </fieldset>

    <script>
    function SaveEmergencyContacts()

    {
    document.frames['ECIframe'].document.getElementById('test').click();
    }
    </script>


    <!-- This is the IFrame snippet -->
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <form action="EmergencyContacts.php" method="post" name="ECForm" id="ECForm"
    onsubmit="alert(document.getElementById('notes_1').value);">
    <input type"text" name="notes_1" id="notes_1" value="This is a test">
    <input type="submit" name="test" id="test" value="Click Me">
    </form>

    <script>
    alert(document.getElementById('notes_1').value);
    </script>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    try:
    Code:
    document.frames['ECIframe'].document.getElementById('ECForm').submit();
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

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