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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onunload

Status
Not open for further replies.

coldfused

Technical User
Jan 27, 2001
2,442
US
Guys I need to pop open a window onunload="". I can do this in the body tag fine no problem.

Unfortunately the page I need to do this on is a form. So if they fill out the form and submit they move on to the thank you page. If they do not submit the form however on close of the form page launch pop up.

Where trying to ask if we gave them all the info they needed to fill out the form if not, what can we do to make it better type thing.

So my problem is if I use onunload="" no matter how the form page ends, successfully or closed it launches the pop up.

Does anyone have a javascript workaround for this?

----------------------------------------
 
Have a global JavaScript var.

Code:
var submitted = false;

In the function that is launched on the UNLOAD event, have it only execute the commands if not submitted:

Code:
function calledOnUnload()
{
 if(!submitted)
 {
  ...
 }
}

Then, with the FORM's ONSUBMIT event, set 'submitted = true;'. Something like this:

Code:
<form name='form1' onsubmit='return setSubmit()'>

...and function setSubmit() would be:

Code:
function setSubmit()
{
 submitted = true;
 return true;
}

This should effectively disable the ONUNLOAD actions from firing when the page is submitted.

'hope that helps.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top