1#! /usr/bin/perl -w 2 3# this is an example of using subs (not coderefs) for your perljax 4# functions 5# 6# NB The CGI::Ajax object DOES NOT need to follow the function 7# declarations, as it does in the coderef example 8 9use strict; 10use CGI::Ajax; 11use CGI; 12 13my $q = new CGI; 14my $pjx = CGI::Ajax->new( 'myfunc' => \&exported_fx); 15print $pjx->build_html($q,\&Show_Form); # this outputs the html for the page 16 17sub exported_fx { 18 my $value_a = shift; 19 my $value_b = shift; 20 $value_a = "" if not defined $value_a; # make sure there's def 21 $value_b = "" if not defined $value_b; # make sure there's def 22 23 if ( $value_a =~ /\D+/ or $value_a eq "" ) { 24 return( $value_a . " and " . $value_b ); 25 } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { 26 return( $value_a . " and " . $value_b ); 27 } else { 28 # got two numbers, so lets multiply them together 29 return( $value_a * $value_b ); 30 } 31} 32 33sub Show_Form { 34 my $html = ""; 35 $html .= <<EOT; 36<HTML> 37<HEAD><title>CGI::Ajax Example</title> 38</HEAD> 39<BODY> 40<form> 41 Enter something: 42 <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] );"><br> 43 44 Enter something else: 45 <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] );"><br> 46 47 <hr> 48 <div id="resultdiv" style="border: 1px solid black; width: 440px; height: 80px; overflow: auto"> 49 </div> 50</form> 51</BODY> 52</HTML> 53EOT 54 return $html; 55} 56