rlm@0: #!C:/strawberry/perl/bin/perl.exe rlm@0: rlm@0: # this is an example of using subs (not coderefs) for your perljax rlm@0: # functions rlm@0: # rlm@0: # NB The CGI::Ajax object DOES NOT need to follow the function rlm@0: # declarations, as it does in the coderef example rlm@0: rlm@0: use strict; rlm@0: use CGI::Ajax; rlm@0: use CGI; rlm@0: rlm@0: my $q = new CGI; rlm@0: my $pjx = CGI::Ajax->new( 'myfunc' => \&exported_fx); rlm@0: print $pjx->build_html($q,\&Show_Form); # this outputs the html for the page rlm@0: rlm@0: sub exported_fx { rlm@0: my $value_a = shift; rlm@0: my $value_b = shift; rlm@0: $value_a = "" if not defined $value_a; # make sure there's def rlm@0: $value_b = "" if not defined $value_b; # make sure there's def rlm@0: rlm@0: if ( $value_a =~ /\D+/ or $value_a eq "" ) { rlm@0: return( $value_a . " and " . $value_b ); rlm@0: } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { rlm@0: return( $value_a . " and " . $value_b ); rlm@0: } else { rlm@0: # got two numbers, so lets multiply them together rlm@0: return( $value_a * $value_b ); rlm@0: } rlm@0: } rlm@0: rlm@0: sub Show_Form { rlm@0: my $html = ""; rlm@0: $html .= < rlm@0: CGI::Ajax Example rlm@0: rlm@0: rlm@0:
rlm@0: Enter something:  rlm@0:
rlm@0: rlm@0: Enter something else:  rlm@0:
rlm@0: rlm@0:
rlm@0:
rlm@0:
rlm@0:
rlm@0: rlm@0: rlm@0: EOT rlm@0: return $html; rlm@0: }