1

Is there a way to call the javascript form submit() function or the JQuery $.submit() function and make sure that it completes the submit process? Specifically, within a form, I am trying to submit a form within an IFrame. From the parent form, I am submitting the IFrame with the following code...

document.frames.IFRAME_Items.document.forms[0].submit();

The parent form then saves and closes. However, currently the IFrame is not completing the post before the parent form saves and closes. Is there any way using a JQuery callback or something in JavaScript to ensure this submit process completes before the parent form closes?

2
  • if your <iframe> is coming from an external website you wont be able to do anything. see: en.wikipedia.org/wiki/Same%5Forigin%5Fpolicy Commented Jan 4, 2010 at 22:06
  • @adardesign This is obviously not the case however, as he is able to access the iframe's form from the parent Commented Jan 4, 2010 at 23:22

2 Answers 2

1
<form onsubmit="return controlParentForm();" id="parentForm">
...
</form>

JS:

var controlSubmitParentForm = 0;
function controlParentForm(){

   var ret = false;

   if (controlSubmitParentForm==0){

     controlSubmitParentForm = 1;
     document.frames.IFRAME_Items.document.forms[0].submit();
     setTimeout(controlParentForm, 200);

   }
   else if (controlSubmitParentForm==1){

     if (document.frames.IFRAME_Items.document.readyState=="complete"){
        controlSubmitParentForm = 2;
        document.getElementById("parentForm").submit();
     }
     setTimeout(controlParentForm, 200);

   }
   else if (controlSubmitParentForm==2){
       // controls for "parentForm"
       ret = true;
       controlSubmitParentForm = 0;
   }

   return ret;

}
Sign up to request clarification or add additional context in comments.

Comments

1

Best what you can do is to submit the iframe's form asynchronously with help of jQuery Form plugin. This way you can wait until the response is returned. It also provides a success callback handler which you can use to submit the parent page's form.

1 Comment

This would be ideal, but I couldn't get either method to work (ajaxForm or ajaxSubmit) with the iFrame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.