wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes java script problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "java script problem" Watch "java script problem" New topic
Author

java script problem

kanumuri koti
Greenhorn

Joined: Apr 05, 2006
Posts: 6
Hi everyone,

I have a data grid and 2 buttons on a page, when a user cancels the window, i want to displat a popup asking the whethere they are sure they want to cancel.

i currently have

<SCRIPT>
function SaveChanges()
{
event.returnValue = "You will loose all unsaved changes, please update details before closing the window.";
}
</SCRIPT>



i call this function on the body like

<body bgColor="#ffffff" MS_POSITIONING="GridLayout" onbeforeunload="SaveChanges()">



Problem is, this message comes up even when clicking the buttons on the page, which is wrong, i want it to happen only when the user closes/cancels the window. Please help

[ December 13, 2006: Message edited by: kanumuri koti ]
[ December 13, 2006: Message edited by: Bear Bibeault ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You need to add a flag to all of the events that cause a post back. (aka set a JavaScript variable onclick) In the SaveChanges you have to check to see if that flag/bit was flipped or not. Than you know if it should be shown.

You will never get the same feel as a client application.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

As a favor I have removed the "very urgent" from the title. Please read this to find out why that's a really bad idea.

You could also use better subjects. Also read this.
[ December 13, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Neerav Narielwala
Ranch Hand

Joined: Dec 08, 2006
Posts: 106
You can also use the "closed" property on the window.opener object to determine whether the window that opened the window in question is still open (are you still with me?). For example:


<script type="text/javascript">
if (window.opener.closed)
alert("You killed my boss!")
else
alert("My boss is still alive!")
</script>


<a href="http://www.java-tips.org/java-tutorials/tutorials/" target="_blank" rel="nofollow">Java Tutorials</a> | <a href="http://www.planet-java.org" target="_blank" rel="nofollow">Java Weblog</a> | <a href="http://computer-engineering.science-tips.org" target="_blank" rel="nofollow">Computing Articles</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java script problem