annotate scripts/pjx_manyret.pl @ 2:d7dd496a4fa6 boosterpack

[svn r4] actual functionality!
author robert
date Tue, 08 Sep 2009 02:45:26 -0400
parents 477258d09353
children
rev   line source
robert@0 1 #!C:/strawberry/perl/bin/perl.exe
robert@0 2
robert@0 3 # this is an example script of how you would use coderefs to define
robert@0 4 # your CGI::Ajax functions, and the methods return multiple results to
robert@0 5 # the page
robert@0 6 #
robert@0 7 # NB The CGI::Ajax object must come AFTER the coderefs are declared.
robert@0 8
robert@0 9 use strict;
robert@0 10 use CGI::Ajax;
robert@0 11 use CGI;
robert@0 12
robert@0 13 my $q = new CGI;
robert@0 14
robert@0 15 my $exported_fx = sub {
robert@0 16 my $value_a = shift;
robert@0 17 my $value_b = shift;
robert@0 18 $value_a = "" if not defined $value_a; # make sure there's def
robert@0 19 $value_b = "" if not defined $value_b; # make sure there's def
robert@0 20
robert@0 21 if ( $value_a =~ /\D+/ or $value_a eq "" ) {
robert@0 22 return( $value_a, $value_b, 'NaN' );
robert@0 23 } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) {
robert@0 24 return( $value_a, $value_b, 'NaN' );
robert@0 25 } else {
robert@0 26 # got two numbers, so lets multiply them together
robert@0 27 return( $value_a, $value_b, $value_a * $value_b );
robert@0 28 }
robert@0 29 };
robert@0 30
robert@0 31
robert@0 32 my $Show_Form = sub {
robert@0 33 my $html = "";
robert@0 34 $html .= <<EOT;
robert@0 35 <HTML>
robert@0 36 <HEAD><title>CGI::Ajax Multiple Return Value Example</title>
robert@0 37 </HEAD>
robert@0 38 <BODY>
robert@0 39 <form>
robert@0 40 Enter something:&nbsp;
robert@0 41 <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['inputa','inputb','resultdiv'] ); return true;"><br>
robert@0 42
robert@0 43 Enter something else:&nbsp;
robert@0 44 <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['inputa','inputb','resultdiv'] ); return true;"><br>
robert@0 45
robert@0 46 <hr>
robert@0 47 <table>
robert@0 48 <tr>
robert@0 49 <td>Input A</td>
robert@0 50 <td>Input B</td>
robert@0 51 <td>Result</td>
robert@0 52 </tr>
robert@0 53 <tr>
robert@0 54 <td>
robert@0 55 <div id="inputa" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div>
robert@0 56 </td>
robert@0 57 <td>
robert@0 58 <div id="inputb" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div>
robert@0 59 </td>
robert@0 60 <td>
robert@0 61 <div id="resultdiv" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div>
robert@0 62 </td>
robert@0 63 </tr>
robert@0 64 </table>
robert@0 65 </form>
robert@0 66 </BODY>
robert@0 67 </HTML>
robert@0 68 EOT
robert@0 69
robert@0 70 return $html;
robert@0 71 };
robert@0 72
robert@0 73 my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx);
robert@0 74 $pjx->JSDEBUG(1);
robert@0 75 print $pjx->build_html($q,$Show_Form); # this outputs the html for the page