Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2006, 08:19 AM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page Events

Hi

I have a page (1 big form) that can either be
1. Closed with the X
2. Exited to previous page with an icon
3. Refreshed

There is validation on the form for fields and warnings if page is closed without saving. THis is done with Validationcheck() code on the onclick events AND onbeforeunload body event.

What is happening is I get 2 warnings for the Exit & refresh, as the local event is fired, then the unload.

Does anyone have a workaround?

Thanks

Andy

 
Old November 7th, 2006, 08:49 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think onbeforeunload always runs, obviouslu onunload only runs if onbeforeunload does not cancel it. Why not just use onbeforeunload? Otherwise have a global Boolean variable, hasValidated, that you set in onbeforeunload. Then check its value in onunload before validating a second time.

--

Joe (Microsoft MVP - XML)
 
Old November 8th, 2006, 07:01 AM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.

Global variable is what I'll do.

<body onLoad="window.validated=false" onBeforeUnload="if (!window.validated) window.returnValue=msg">

And I will set the validated flag in my validation script.

Andy






Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Events??? Dmitriy ASP.NET 3.5 Professionals 1 September 24th, 2008 03:28 PM
Events for the page navigatore button MyIssues_2005 Crystal Reports 0 March 1st, 2007 07:19 AM
Events bschleusner C# 2005 2 February 26th, 2007 05:25 AM
Delay mouse events until page loaded? John K. King Javascript How-To 1 May 11th, 2005 11:19 AM
help with Events egiblock JSP Basics 0 October 6th, 2003 11:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.