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

G

Grehom

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;
 
X

xhoster

Grehom said:
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.
 
G

Grehom

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.

...


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.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top