cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Popup to avoid losing unsaved data

Former Member
0 Likes
1,639

Hi,

I'm developing a BSP where the user will modify data and I'd like a popup to appear when the 'Back' button is pressed and there have been usaved modifications.

Basically it should be a popup with a 'You have modified the data. Are you sure you want to leave the page without saving?' or something like that and two buttons YES/NO (the yes button should execute an event and the no just close the popup).

Can you help me with it?

Many thanks in advance

Carles

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Thanks Sebastian, that's what I needed. But now, how I process the event? I mean, where do I write the subsequent code for the Accept and Cancel buttons?

Many thanks

Former Member
0 Likes

Hi again,

that's the best of it - you hav nothing to do

If you have your button supplied with onClick like:


<htmlb:button id="..."
onClick = "YourEvent"
onClientClick = "confirm('Do you really want to?');" 
/>

... a Click will do the following:

1. confirmation dialog will be display waitig for a user action

2. a) when user clicks OK - the script returns TRUE and the request will be sent to the server

2. b) when user clicks CANCEL - the script returns FALSE and nothing happens

The BSP-eventlibrary looks automatically for these client events.

Regards,

Sebastian

(Sorry, wrote about htmlb:inputfield in my first post - I meant htmlb:button of course.)

Answers (3)

Answers (3)

Former Member
0 Likes

Ok,

I've written the code inside the onClientClick:

onClientClick = "if(confirm('Do you really want to?')){document.location.href='main_gestors.htm?NUMPERS=<%= numpers %>';}"

and it does what I wanted

Thanks to you all!

Former Member
0 Likes

Thanks, but I think I explained myself wrong.

When I said 'Back' button I meant a button created with htmlb:button. It's whenever I click that button that the event should be triggered.

Carles

raja_thangamani
Active Contributor
0 Likes

Look at this blog from Eddy, It will solve your problem...

/people/eddy.declercq/blog/2006/03/20/wake-me-up-before-you-go-go

<i>*Reward each useful answer</i>

Raja T

Former Member
0 Likes

Hi,

use onClientClick attribut of htmlb:button, e.g.:

<htmlb:inputField id="..."

onClientClick = "confirm('Do you really want to?');" />

Regards,

Sebastian

Former Member
0 Likes

Hi,

Are you talking about the Browser back button ?

If yes, then i have a solution for Internet Explorer...

Try this :

<html>
<script language = "javascript">

window.onbeforeunload = bunload;
function bunload(){
  mess = "You will lose all information providednduring navigation of this site";
  return mess;
}
function confirmEvent()
{
	alert("Function called");
	if(!confirm('Do you really want to proceed?'))
	{
		window.onbeforeunload = false
		return false;
	}
}
function test()
{
alert("Hellio");
document.frm.t1[2].style.background = "rgb(231,220,24)";
var arr = document.frm.elements;
var i;
for(i=0;i<arr.length;i++)
{
	if(arr<i>.type == "text")
	{
		if(!arr<i>.disabled)
		{
			alert(arr<i>.value);
		}
	}


}
alert(document.frm.t1[3].value);
}
</script>
<body>
<form name="frm">
<input type="text" name="t1" size=5 value="Hello1" disabled="true">
<input type="text" name="t1" size=5 value="Hello2" style="font-family: Verdana;font-size: 10; align=middle; height: 17px;border: solid rgb(220,225,260) 1px">
<input type="text" name="t1" size=5 value="Hello3">
<input type="button" name="b1" value="Click here" onClick="test()">
</form>
</body>
</html>