By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

confirm update popup?

P: n/a
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

--

--------
Senior UNIX Admin
O'Leary Computer Enterprises
dk******@olearycomputers.com (w) 630-904-6098 (c) 630-248-2749
resume: http://home.comcast.net/~dkoleary/resume.html
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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?')">

Jul 23 '05 #2

P: n/a
Doug O'Leary wrote:
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.
[...]
--
Rob
Jul 23 '05 #3

P: n/a
On 2005-06-26, Lee <RE**************@cox.net> wrote:

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

--

--------
Senior UNIX Admin
O'Leary Computer Enterprises
dk******@olearycomputers.com (w) 630-904-6098 (c) 630-248-2749
resume: http://home.comcast.net/~dkoleary/resume.html
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.