view scripts/pjx_manyret.pl @ 4:90181bbf7a0c boosterpack

[svn r6] added Dylan's awesome stuff.
author robert
date Tue, 08 Sep 2009 06:05:47 -0400
parents 477258d09353
children
line wrap: on
line source
1 #!C:/strawberry/perl/bin/perl.exe
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.
9 use strict;
10 use CGI::Ajax;
11 use CGI;
13 my $q = new CGI;
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
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 };
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>
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>
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
70 return $html;
71 };
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