confirm update popup?

D

Doug O'Leary

Hey, all;

Apparently, I'm missing the concept. I'm writing a web app in perl
to manage nagios configuration files. One of the things I'd like to
do is to confirm an update via a popup window prior to writing out
changes.

My first whack at that goal isn't working out too well. I have the
following javascript in one of the pages:

function confirm_update()
{ var width = 400;
var height = 300;
var Rc = false;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var winFeatures = "width=" + width + ",height="+height +
",status,resizable,left="+left+",top="+top+
",screenX="+left+",screenY="+top;
var cwin = window.open("","confirm_update", winFeatures);
var ncontent="<html><head><title>Confirm update</title>"
ncontent += "</head>"
ncontent += "<body><h1>Confirm Update</h1>";
ncontent += "<table align='center'><<tr>>";
ncontent += "<<td>><button ";
ncontent += " onclick='window.close(); return true'>";
ncontent += " <big>Confirm</big></button>";
ncontent += "<<td>><button ";
ncontent += " onclick='window.close(); return false'>";
ncontent += " <big>Don't do it!</big></button>";
ncontent += "</<tr>></table></body></html>";
cwin.document.write(ncontent);
cwin.document.close();
}

And it's called via the onclick method in the submit button:

<button type="submit" onclick="return (confirm_update())">
<big>Update</big></button>

I've played with this a couple of different ways. The window pops up
like it's supposed to. I can get the function to always validate or
always fail; however, it's never based on the button press.

I know this is because the function is returning before the user even
sees the confir/refute buttons much less presses one of them. I'm
obviously much more used to procedural languages and just can't quite
wrap my brain around a stateless protocol.

I would think this would be a fairly common function. Can someone
point me to some code snippets that would get me started on the right
path?

Thanks for any hints/tips/suggestions...

Doug O'Leary
 
L

Lee

Doug O'Leary said:
Hey, all;

Apparently, I'm missing the concept. I'm writing a web app in perl
to manage nagios configuration files. One of the things I'd like to
do is to confirm an update via a popup window prior to writing out
changes.

My first whack at that goal isn't working out too well. I have the
following javascript in one of the pages:

function confirm_update()
{ var width = 400;
var height = 300;
var Rc = false;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var winFeatures = "width=" + width + ",height="+height +
",status,resizable,left="+left+",top="+top+
",screenX="+left+",screenY="+top;
var cwin = window.open("","confirm_update", winFeatures);
var ncontent="<html><head><title>Confirm update</title>"
ncontent += "</head>"
ncontent += "<body><h1>Confirm Update</h1>";
ncontent += "<table align='center'><<tr>>";
ncontent += "<<td>><button ";
ncontent += " onclick='window.close(); return true'>";
ncontent += " <big>Confirm</big></button>";
ncontent += "<<td>><button ";
ncontent += " onclick='window.close(); return false'>";
ncontent += " <big>Don't do it!</big></button>";
ncontent += "</<tr>></table></body></html>";
cwin.document.write(ncontent);
cwin.document.close();
}

And it's called via the onclick method in the submit button:

<button type="submit" onclick="return (confirm_update())">
<big>Update</big></button>

I've played with this a couple of different ways. The window pops up
like it's supposed to. I can get the function to always validate or
always fail; however, it's never based on the button press.

I know this is because the function is returning before the user even
sees the confir/refute buttons much less presses one of them. I'm
obviously much more used to procedural languages and just can't quite
wrap my brain around a stateless protocol.

I would think this would be a fairly common function. Can someone
point me to some code snippets that would get me started on the right
path?

If you want submission to depend on the return value of
an event handler, use the onSubmit event handler of the
form, not the onclick handler of the submit button.

Your function confirm_update() doesn't return a value, so
"return confirm_update()" isn't going to control anything.

The window has a confirm() method that does what you want:
<form name="whatever" ... onsubmit="return confirm('Update?')">
 
R

RobG

Doug said:
Hey, all;

Apparently, I'm missing the concept. I'm writing a web app in perl
to manage nagios configuration files. One of the things I'd like to
do is to confirm an update via a popup window prior to writing out
changes.

A much simpler 'confirm' dialog is:

<form ... onsubmit="return confirm('Do update?');">

Zero issues with pop-up blockers (some block requested pop-ups too).

[...]
I know this is because the function is returning before the user even
sees the confir/refute buttons much less presses one of them. I'm
obviously much more used to procedural languages and just can't quite
wrap my brain around a stateless protocol.

Using a 'confirm' dialog gives you a modal dialog.


[...]
 
D

Doug O'Leary

The window has a confirm() method that does what you want:
<form name="whatever" ... onsubmit="return confirm('Update?')">

Lee and Rob, thanks. That's exactly what I was looking for.
Simple and elegant... Too cool. Thanks again.

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top