views:

236

answers:

2

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?

+1  A: 

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.

BalusC
This would be ideal, but I couldn't get either method to work (ajaxForm or ajaxSubmit) with the iFrame.
SaaS Developer
+1  A: 
<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;

}
andres descalzo