confirm update popup?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug O'Leary

    confirm update popup?

    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((scree n.availWidth/2) - (width/2));
    var top = parseInt((scree n.availHeight/2) - (height/2));
    var winFeatures = "width=" + width + ",height="+heig ht +
    ",status,resiza ble,left="+left +",top="+top +
    ",screenX="+lef t+",screenY="+t op;
    var cwin = window.open("", "confirm_update ", winFeatures);
    var ncontent="<html ><head><title>C onfirm update</title>"
    ncontent += "</head>"
    ncontent += "<body><h1>Conf irm Update</h1>";
    ncontent += "<table align='center'> <<tr>>";
    ncontent += "<<td>><but ton ";
    ncontent += " onclick='window .close(); return true'>";
    ncontent += " <big>Confirm</big></button>";
    ncontent += "<<td>><but ton ";
    ncontent += " onclick='window .close(); return false'>";
    ncontent += " <big>Don't do it!</big></button>";
    ncontent += "</<tr>></table></body></html>";
    cwin.document.w rite(ncontent);
    cwin.document.c lose();
    }

    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
    dkoleary@oleary computers.com (w) 630-904-6098 (c) 630-248-2749
    resume: http://home.comcast.net/~dkoleary/resume.html
  • Lee

    #2
    Re: confirm update popup?

    Doug O'Leary said:[color=blue]
    >
    >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((scree n.availWidth/2) - (width/2));
    > var top = parseInt((scree n.availHeight/2) - (height/2));
    > var winFeatures = "width=" + width + ",height="+heig ht +
    > ",status,resiza ble,left="+left +",top="+top +
    > ",screenX="+lef t+",screenY="+t op;
    > var cwin = window.open("", "confirm_update ", winFeatures);
    > var ncontent="<html ><head><title>C onfirm update</title>"
    > ncontent += "</head>"
    > ncontent += "<body><h1>Conf irm Update</h1>";
    > ncontent += "<table align='center'> <<tr>>";
    > ncontent += "<<td>><but ton ";
    > ncontent += " onclick='window .close(); return true'>";
    > ncontent += " <big>Confirm</big></button>";
    > ncontent += "<<td>><but ton ";
    > ncontent += " onclick='window .close(); return false'>";
    > ncontent += " <big>Don't do it!</big></button>";
    > ncontent += "</<tr>></table></body></html>";
    > cwin.document.w rite(ncontent);
    > cwin.document.c lose();
    >}
    >
    >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?[/color]

    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="retur n confirm('Update ?')">

    Comment

    • RobG

      #3
      Re: confirm update popup?

      Doug O'Leary wrote:[color=blue]
      > 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.[/color]

      A much simpler 'confirm' dialog is:

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

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

      [...]
      [color=blue]
      > 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.[/color]

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


      [...]
      --
      Rob

      Comment

      • Doug O'Leary

        #4
        Re: confirm update popup?

        On 2005-06-26, Lee <REM0VElbspamtr ap@cox.net> wrote:[color=blue]
        >
        > The window has a confirm() method that does what you want:
        ><form name="whatever" ... onsubmit="retur n confirm('Update ?')">
        >[/color]

        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
        dkoleary@oleary computers.com (w) 630-904-6098 (c) 630-248-2749
        resume: http://home.comcast.net/~dkoleary/resume.html

        Comment

        Working...