Pop up Confirmation Box


 
Thread Tools Search this Thread
Top Forums Web Development Pop up Confirmation Box
# 1  
Old 08-06-2008
Pop up Confirmation Box

Hi,

I was writing a simple web application using Perl -CGI. When users try to do some operations, I wanted like a pop-up confirmation box. Is this possible with Perl-CGI?

Thanks in advance.

Regards,
garric
# 2  
Old 08-06-2008
The standard approach is to use the window.confirm() DOM Javascript method.

DOM:window.confirm - MDC
# 3  
Old 08-06-2008
Thanks. Looks like this will work for me. But how do I integrate it into a CGI script?

Regards,
garric
# 4  
Old 08-06-2008
Because what CGI.pm does is to simply print output to the STDOUT (this is the protocol of CGI itself), you can always print the needed Javascript from your program.

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

This should be printed somewhere inside the "head" or "body" tags. This prints a Javascript function definition, but just like a Perl subroutine definition, it is not called immediately. It must still be called from somewhere in the program.

If you still wish to use CGI.pm to generate the entire HTML output after reading this post (which I don't really recommend because I think that facade doesn't do much good), CGI.pm exposes some attributes that correspond to standard Javascript event handlers applied to HTML objects that you can use to execute custom Javascript just like the one above. You can find more information at:

CGI - perldoc.perl.org

Then you can do something like this to install the handler:

Code:
print button(-name=>'button_name',
			  -value=>'user visible label',
			  -onClick=>"return confirmOK()");

If you think that printing javascript text from your Perl program is very ugly, like I do, use a template system to generate the returned content rather than using the "tree-building" mode of CGI.pm (but do use CGI.pm to generate headers, capture GET/POST/COOKIE params etc. - that's good). My favourite:

Template Toolkit Home Page

I advise you to really find out more about HTML and Javascript or your concepts may not allow you to go too much further, no matter you are going the CGI.pm route, template route or some other approaches. Because Javascript is complex, I suggest you look for resources to learn on your own but definitely don't look into the Perl docs for that!
# 5  
Old 08-08-2008
Thanks for this info. Yes, I think I need to go back and understand Javascript and HTML better.

As for this problem, this is what I wrote (still unsuccessfully)
Code:
my $display_form = new CGI;
$JSCRIPT="function confirmOk() { return window.confirm('Confirm deletion?'); }";

print $display_form->header("text/html");
print $display_form->start_html(
                                                -meta=>{'http-equiv'=>'Content-Language','content'=>'en-us'},
                                                -script=>$JSCRIPT);
print $display_form->start_form(-title=>"Operation", -style=>'font-size: 9pt; color:  #000000 ; font-family: Tahoma', -action=>"./operation.pl", -method=>"POST");
print $display_form->submit(-name=>'Operation', -onClick=>"return confirmOK()");

Clicking on the submit button still doesn't result in the pop-up. Do you see anything I am missing here?

Regards,
garric
# 6  
Old 08-08-2008
Oh, sorry. Should be

Code:
return confirmOk()

Didn't notice the wrong casing. Javascript is case-sensitive.
# 7  
Old 08-08-2008
that worked, thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Don't receive confirmation mail.

Hi Folks, I just recently registered with the username _Kaede. Unfortunately, I didn't receive any confirmation mail also not when I changed to another address. Help is very appreciated. Thanks and kind regards :) (2 Replies)
Discussion started by: Unregistered
2 Replies

2. Web Development

Pop up confirmation box / perl cgi

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 : print header; print <<EOF; <script type="text/javascript"> function confirmOk() { return... (0 Replies)
Discussion started by: terrykhatri531
0 Replies

3. UNIX for Dummies Questions & Answers

How to shutdown Linux box with user confirmation?

Hi Guru's Am looking for linux reboot command which get executed after user confirmation .Can someone please help me with this.:confused::confused::confused: (6 Replies)
Discussion started by: kapil514
6 Replies

4. Shell Programming and Scripting

Confirmation while deleting a file

Hi All, While am deleting a file in unix by using the command rm it's deleting the file directly IT's have to ask the user while deleting like do you want to delete filename y or N ? Kindly help on this. Thanks Thelak (2 Replies)
Discussion started by: thelakbe
2 Replies

5. Shell Programming and Scripting

twice confirmation in the script

from one script invoke another script will need to do double confirmation like: 'y' and 'y' exp: echo 'y' | /a/b/c.sh only input 1 'y' in the c.sh, but the c.sh required 2 'y' (twice confirmation) is there anyway get resolve this issue? please help (2 Replies)
Discussion started by: kinx
2 Replies

6. Solaris

Netbackup Solaris Client confirmation

Greetings, I have a bunch of Solaris servers that are running Netbackup as a client. I set them up and my backup admin has confirmed that they are being backed up. But what I want to be able to do is run a command from each Solaris client to see some proof from the client side that the files... (1 Reply)
Discussion started by: BrewDudeBob
1 Replies

7. Shell Programming and Scripting

Search and Replace with Confirmation

Hi, I have created a script which searches and replace the searched text from any file in directory. I want to add a functionality where before replacing the text, script shows the line with the searched text and ask for user confirmation before replacing the text. Can this be done using SED... (18 Replies)
Discussion started by: Abhinav Tyagi
18 Replies

8. Shell Programming and Scripting

Pop up dialog box on remote computers

I need to send out messages to over 100 clients in my sector. I want it to pop up a dialog box letting them know to save work and log out. I have the reboot script created just need the warning please. Thanks (35 Replies)
Discussion started by: deaconf19
35 Replies

9. Forum Support Area for Unregistered Users & Account Problems

need email confirmation resent

we had a power outage shortly after i registered... so my mail server was down for a while... could i get the email confirmation for hackware --> resent please...? thanx... ...william.o.yates...email removed (3 Replies)
Discussion started by: hackware
3 Replies

10. UNIX for Dummies Questions & Answers

Mail delivery confirmation

If I am sending mail with this command: mail .......@whatever.com < filename, is it possible to get delivery confirmation? Thanks (3 Replies)
Discussion started by: CSGUY
3 Replies
Login or Register to Ask a Question