#! /usr/bin/perl -w # this is an example script of how you would use coderefs to define # your CGI::Ajax functions. # # NB The CGI::Ajax object must come AFTER the coderefs are declared. use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $exported_fx = sub { my $value_a = shift; my $value_b = shift; $value_a = "" if not defined $value_a; # make sure there's def $value_b = "" if not defined $value_b; # make sure there's def if ( $value_a =~ /\D+/ or $value_a eq "" ) { return( $value_a . " and " . $value_b ); } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { return( $value_a . " and " . $value_b ); } else { # got two numbers, so lets multiply them together return( $value_a * $value_b ); } }; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Example
Enter something: 
Enter something else: 

EOT return $html; }; my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page