CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Adding a pop up confirmation box

 



terrykhatri531
User

Jul 6, 2014, 2:00 AM

Post #1 of 3 (493 views)
Adding a pop up confirmation box Can't Post

Hi,



I need to add confirmation pop up msg box before deleting the record from database, I have added following snippets to my code but its not working for me, your help will be much appreciated :




Code
  

print header;

print <<EOF;

<script type="text/javascript">

function confirmOk() {

return window.confirm("Confirm deletion?");

}

</script>

EOF





And




Code
  

# If the form was properly submitted, save the data

if ($input{"go"} eq "DELETE") {



print button(-name=>'Delete',

-value=>'DO you really want to delete it ?',

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



$query = "DELETE ....










Following is the complete script :


Code
 
#!/usr/local/bin/perl

use CGI;
use DBI;

# Make up a pulldown menu of all known patients
$db_handle = DBI -> connect("DBI:Pg:dbname=northwind;
host=localhost",
"postgres",
"postgres",
{'RaiseError' => 1});

$query = "SELECT
\"EmployeeID\" AS empid,
\"FirstName\"::text || ' ' ||\"LastName\"::text AS name
FROM
\"Employees\"";

$db_handle->do("SET search_path to northwind") or die;

$qh = $db_handle->prepare($query);
$qh->execute;

while (@row = $qh->fetchrow) {
$hh .= "<option value=$row[0]>$row[1]</option>\n";
}

# Send out the header and form
print "content-type: text/html\n\n";
print <<"HEADER";
<html>
<head>
<title>Delete an employee record</title>
<body bgcolor=pink text=#3300CC border=2 bordercolor=pink >
<h1 style="color:3300CC;">Delete an employee</h1>

<style type="text/css">
.container {
width: 500px;
clear: both;
}
.container input {
width: 100%;
clear: both;
}

</style>

</head>
<div class="container">
<form method=POST>
Select Employee name to delete :<select name=empid>$hh</select><br>
<input type=submit name=go value=DELETE>
</div>
</form><hr>
HEADER

print header;
print <<EOF;
<script type="text/javascript">
function confirmOk() {
return window.confirm("Confirm deletion?");
}
</script>
EOF



# Read information from the form
read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
@pairs = split(/&/,$buffer);
foreach (@pairs) {
($n,$v) = split(/=/);
$v =~ tr/+/ / ;
$v =~ s/%(..)/pack("C",hex($1))/ge;
$input{$n} = $v;
}

# If the form was properly submitted, save the data
if ($input{"go"} eq "DELETE") {

print button(-name=>'Delete',
-value=>'DO you really want to delete it ?',
-onClick=>"return confirmOk()");


$query = "DELETE
FROM
\"Employees\"
WHERE
\"EmployeeID\"="." \'$input{empid}\'";

$db_handle -> do($query);
$action = "Record saved - $query";


# If the form has not been submitted, ask for data
} else {
$action = "Please complete form";
}

# Standard links to the rest of the application
print <<"FOOTER";
<b>$action</b>
<hr>
Jump to - <a href=http://localhost/perlproj/cgi-bin/emp2.pl>View Employees Listing</a><br>
Jump to - <a href=http://localhost/perlproj/cgi-bin/addemp.pl>Add an Employee</a><br>
Jump to - <a href=http://localhost/perlproj/cgi-bin/updatephoto.pl>Add or update Employee Photo</a><br>
<hr>
Edited by Terry on July, 06 2014.
</body></html>
FOOTER



Many thanks

Terry


(This post was edited by terrykhatri531 on Jul 6, 2014, 3:27 AM)


Laurent_R
Veteran / Moderator

Jul 6, 2014, 4:19 AM

Post #2 of 3 (485 views)
Re: [terrykhatri531] Adding a pop up confirmation box [In reply to] Can't Post

Cross posted on Perl Monks. It is considered polite to inform people about cross-posting questions, to avoid duplication of work in various parts of the Net.


terrykhatri531
User

Jul 6, 2014, 8:38 AM

Post #3 of 3 (477 views)
Re: [Laurent_R] Adding a pop up confirmation box [In reply to] Can't Post

A BIG SORRY !!!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives