in reply to Create pop up error message in Perl

CGI::Ajax may be helpful. Here are a couple of quick examples to play around with. First is an example without javascript that prints to the page instead of a popup. (Update: More accurately said as "without having to write any javascript yourself", thanks almut)
#! /usr/bin/perl use strict; use warnings; use CGI; use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&too_many_nums ); print $pjx->build_html( $cgi, \&Show_HTML); sub too_many_nums { my $output = ""; my $input = shift; if( length($input) > 10 ) { $output = "Too many numbers!"; } return( $output ); } sub Show_HTML { my $html = <<EOHTML; <HTML> <BODY> Enter something: <input type="text" name="val1" id="val1" onkeyup="exported_fun +c( ['val1'], ['resultdiv'] );"> <br> <div id="resultdiv"></div> </BODY> </HTML> EOHTML return $html; }
And here is an example that uses a javascript popup.
#! /usr/bin/perl use strict; use warnings; use CGI; use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&too_many_nums ); print $pjx->build_html( $cgi, \&Show_HTML); sub too_many_nums { my $output = ""; my $input = shift; if( length($input) > 10 ) { $output = "Too many numbers!"; } return( $output ); } sub Show_HTML { my $html = <<EOHTML; <HTML> <BODY> <head> <script type="text/javascript"> function disp_alert() { var input = arguments[0] if( input != "" ) { alert(input); } } </script> </head> Enter something: <input type="text" name="val1" id="val1" onkeyup="exported_fun +c( ['val1'], [disp_alert] );"> <br> <div id="resultdiv"></div> </BODY> </HTML> EOHTML return $html; }
hth

Replies are listed 'Best First'.
Re^2: Create pop up error message in Perl
by almut (Canon) on Feb 11, 2009 at 16:17 UTC
    First is an example without javascript

    I know what you mean... but strictly speaking, this is not without Javascript. CGI::Ajax uses Javascript code (auto-generated and embedded in the page) to glue the server-side Perl routines to the client-side events.  Also, onkeyup="..." generally wouldn't work without Javascript enabled.

    Although Ajax doesn't necessarily require Javascript, it always needs some dynamic/scripting environment client-side (alternatives to Javascript are for example VBScript or EGL).