Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 7th, 2006, 07:19 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
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

Reply With Quote
  #2 (permalink)  
Old November 7th, 2006, 07:49 AM
joefawcett's Avatar
Wrox Author
Points: 9,712, Level: 42
Points: 9,712, Level: 42 Points: 9,712, Level: 42 Points: 9,712, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,066
Thanks: 1
Thanked 36 Times in 35 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)
Reply With Quote
  #3 (permalink)  
Old November 8th, 2006, 06:01 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:19 AM
Events bschleusner C# 2005 2 February 26th, 2007 04: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



All times are GMT -4. The time now is 02:01 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.