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 |