rlm@0: #!C:/strawberry/perl/bin/perl.exe rlm@0: rlm@0: # this is an example script of how you would use coderefs to define rlm@0: # your CGI::Ajax functions, and the methods return multiple results to rlm@0: # the page rlm@0: # rlm@0: # NB The CGI::Ajax object must come AFTER the coderefs are declared. 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: rlm@0: my $exported_fx = sub { 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, $value_b, 'NaN' ); rlm@0: } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { rlm@0: return( $value_a, $value_b, 'NaN' ); rlm@0: } else { rlm@0: # got two numbers, so lets multiply them together rlm@0: return( $value_a, $value_b, $value_a * $value_b ); rlm@0: } rlm@0: }; rlm@0: rlm@0: rlm@0: my $Show_Form = sub { rlm@0: my $html = ""; rlm@0: $html .= <<EOT; rlm@0: <HTML> rlm@0: <HEAD><title>CGI::Ajax Multiple Return Value Example</title> rlm@0: </HEAD> rlm@0: <BODY> rlm@0: <form> rlm@0: Enter something: rlm@0: <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['inputa','inputb','resultdiv'] ); return true;"><br> rlm@0: rlm@0: Enter something else: rlm@0: <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['inputa','inputb','resultdiv'] ); return true;"><br> rlm@0: rlm@0: <hr> rlm@0: <table> rlm@0: <tr> rlm@0: <td>Input A</td> rlm@0: <td>Input B</td> rlm@0: <td>Result</td> rlm@0: </tr> rlm@0: <tr> rlm@0: <td> rlm@0: <div id="inputa" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div> rlm@0: </td> rlm@0: <td> rlm@0: <div id="inputb" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div> rlm@0: </td> rlm@0: <td> rlm@0: <div id="resultdiv" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div> rlm@0: </td> rlm@0: </tr> rlm@0: </table> rlm@0: </form> rlm@0: </BODY> rlm@0: </HTML> rlm@0: EOT rlm@0: rlm@0: return $html; rlm@0: }; rlm@0: rlm@0: my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx); rlm@0: $pjx->JSDEBUG(1); rlm@0: print $pjx->build_html($q,$Show_Form); # this outputs the html for the page