how can I pass javascript window.confirm result back to my perl cgiprogram

Discussion in 'Perl Misc' started by Grehom, May 14, 2008.

  1. Grehom

    Grehom Guest

    I want to know whether the user confirmed the button press, or if they
    cancelled it. This is my trial script - I have tried a lot of
    variations on this and searched for similar online, thanks for any
    help.

    #!/usr/bin/perl

    use strict;
    use warnings;
    use English qw( OUTPUT_AUTOFLUSH );

    use CGI qw/:standard *table/;

    $ENV{PATH} = "/bin:/usr/bin"; # Straight and narrow path

    # alternative for $|, if set to non-zero forces a flush after every
    write
    # or print on the currently selected output handle
    $OUTPUT_AUTOFLUSH = 1; # unbuffer STDOUT

    # Here's the javascript code that we include in the document.
    my $JSCRIPT = <<"END_OF_JAVASCRIPT";
    function ConfirmWin() {
    var response = window.confirm("Are you sure you want to delete
    this record?");
    if (response) {
    window.alert("Delete confirmed, record will be deleted.");
    return true;
    }
    else {
    window.alert("Delete NOT confirmed, no deletion will occur.");
    return false;
    }
    }
    END_OF_JAVASCRIPT

    my $user_name = "";

    print header,
    start_html( -title => "Test Confirm", -script => $JSCRIPT, ),
    h1("Test Confirm"),
    start_form,
    table(
    Tr(
    td( "User Name: ", ),
    td( textfield( -name => 'user_name', ), ),
    ),
    ),
    p,
    submit( -name => 'delete_record', -label => 'Delete Record', -
    onClick => "ConfirmWin()");

    end_form,
    end_html;

    warn "delete button pressed: ", param('delete_record');

    exit;
    Grehom, May 14, 2008
    #1
    1. Advertising

  2. Grehom

    Guest

    Re: how can I pass javascript window.confirm result back to my perl cgi program

    Grehom <> wrote:
    > I want to know whether the user confirmed the button press, or if they
    > cancelled it. This is my trial script - I have tried a lot of
    > variations on this and searched for similar online, thanks for any
    > help.


    If that is what you really want to do, then have the javascript change the
    setting of some form element, which will then be submitted to CGI just like
    any other form element is.

    ....

    > submit( -name => 'delete_record', -label => 'Delete Record',
    > -onClick => "ConfirmWin()");


    This submits unconditionally. If you change that to

    -onClick => "return ConfirmWin()");

    then if the person does not confirm, the form will not be submitted.
    But since the form is not submitted, the CGI is not invoked and hence
    can't tell whether it was not invoked because submit was not pressed,
    as opposed to being not invoked because submit was pressed but then
    canceled.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
    , May 14, 2008
    #2
    1. Advertising

  3. Grehom

    Grehom Guest

    Re: how can I pass javascript window.confirm result back to my perlcgi program

    On May 14, 4:39 pm, wrote:
    > Grehom <> wrote:
    > > I want to know whether the user confirmed the button press, or if they
    > > cancelled it. This is my trial script - I have tried a lot of
    > > variations on this and searched for similar online, thanks for any
    > > help.

    >
    > If that is what you really want to do, then have the javascript change the
    > setting of some form element, which will then be submitted to CGI just like
    > any other form element is.
    >
    > ...
    >
    > > submit( -name => 'delete_record', -label => 'Delete Record',
    > > -onClick => "ConfirmWin()");

    >
    > This submits unconditionally. If you change that to
    >
    > -onClick => "return ConfirmWin()");
    >
    > then if the person does not confirm, the form will not be submitted.
    > But since the form is not submitted, the CGI is not invoked and hence
    > can't tell whether it was not invoked because submit was not pressed,
    > as opposed to being not invoked because submit was pressed but then
    > canceled.
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > The costs of publication of this article were defrayed in part by the
    > payment of page charges. This article must therefore be hereby marked
    > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    > this fact.



    Thanks, that's great, wouldn't have dreamt of trying that.
    Grehom, May 14, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Billy
    Replies:
    1
    Views:
    673
    Saravana [MVP]
    Nov 27, 2003
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    pass values back to parent window

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Dec 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,374
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Dec 7, 2004
  3. Chris Ianson
    Replies:
    15
    Views:
    36,986
    Randy Webb
    Mar 20, 2006
  4. darrel
    Replies:
    19
    Views:
    1,127
    Vijay Kumar
    Oct 22, 2010
  5. Michael Tan
    Replies:
    32
    Views:
    925
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page