Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how can I pass javascript window.confirm result back to my perl cgiprogram

Reply
Thread Tools

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

 
 
Grehom
Guest
Posts: n/a
 
      05-14-2008
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;
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      05-14-2008
Grehom <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Grehom
Guest
Posts: n/a
 
      05-14-2008
On May 14, 4:39 pm, (E-Mail Removed) wrote:
> Grehom <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
i = 10; result = ++i - --i; How result become ZERO Lakshmi Sreekanth C Programming 52 09-23-2010 07:41 AM
Is the result of valid dynamic cast always equal to the result ofcorrespondent static cast? Pavel C++ 7 09-18-2010 11:35 PM
simulation result is correct but synthesis result is not correct J.Ram VHDL 7 12-03-2008 01:26 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM



Advertisments