annotate BoosterPack/scripts/pjx_manyret.pl @ 0:0d795f02a8bb tip

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