Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Child Not (always) submitting while closing

Status
Not open for further replies.

vinayak

Technical User
Sep 17, 2001
50
IN
Hi,
I have a child window which submits a form, then closes. The problem is, sometimes form is not submitting at all. CONFIG: IE 5, WIN 2K, TOMCAT 3.0.

Child JSP:
........
........
<SCRIPT LANGUAGE=&quot;JavaScript&quot; PURPOSE=&quot;Include&quot; SRC=&quot;FeedBack.js&quot;></SCRIPT>
<BODY ......... onload=&quot; LoadFeedbackForm();&quot;>
<FORM name=&quot;FeedbackForm&quot; method=&quot;post&quot; action=&quot;&quot; onsubmit=&quot;JavaScript:return SubmitFeedback();&quot; >
....................................................
....................................................
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; TABINDEX=&quot;4&quot; >
<INPUT TYPE=&quot;button&quot; NAME=&quot;Close2&quot; VALUE=&quot;Cancel&quot; TABINDEX=&quot;6&quot; onClick=&quot;self.close();&quot;>
</FORM>
</BODY>
........
........

FeedBack.js:
var submitFlag=false; // check for multiple submissions
function SubmitFeedback()
{
var ls_form=document.FeedbackForm;
if(submitFlag==false)
{
submitFlag=true;
ls_form.action = 'Feedback?ps_Action=Feedback';
//ls_form.submit(); //This is the point of submission
window.self.close();
return true;
}
else
return false;

}

 
I have a similar problem. I have read elsewhere that the form submission doesn't always complete before the window is closed. I tried using the setTimeout function but that didn't work. I ended up writing a function to delay the window closing for 3 seconds to allow sufficient time for form submittal.

function pause(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime)
return;
}
}

Then call this function after form submittal but before the window closing event. You may want to wrap it all in a confirm to warn the user there will be a delay.

if(confirm(&quot;Data will be submitted for update.\n&quot; +
&quot;This will take aproximately 3 seconds.&quot; +
&quot;\nDo you wish to continue?&quot;)) {
form.submit();
pause(3000);
window.close();
}else {
return false;
}

This isn't pretty, but it's the best solution I have found in my few weeks of writing Javascript.

If anyone has a better idea, I'm all ears.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top