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