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