comparison BoosterPack/scripts/.svn/text-base/pjx_chained.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 # pjx_chained.pl: Multiple exported perl subs, and the exported
4 # functions are chained to an event, like this...
5 # onclick="func1(['in1'],['out1']); func2(['in1'],['out2']);"
6
7 use strict;
8 use CGI::Ajax;
9 use CGI;
10
11 my $q = new CGI;
12
13 my $multiply = sub {
14 my $a = shift;
15 my $b = shift;
16 return $a * $b;
17 };
18
19 my $divide = sub {
20 my $a = shift;
21 my $b = shift;
22 return $a / $b;
23 };
24
25 my $Show_Form = sub {
26 my $html = "";
27 $html .= <<EOT;
28 <HTML>
29 <HEAD><title>CGI::Ajax Chained function Example</title>
30 </HEAD>
31 <BODY>
32 <form>
33 Enter Number:
34 <input type="text" id="val1" size="6" value=2
35 onkeyup="divide(['val1','val2'], ['out1']); multiply(['val1','val2'], ['out2']);">
36
37 <input type="text" id="val2" size="6" value = 7
38 onkeyup="divide(['val1','val2'], ['out1']); multiply(['val1','val2'], ['out2']);"><br/><br/>
39
40 <input type=text id="out1">
41 <input type=text id="out2">
42
43
44 </form>
45 </BODY>
46 </HTML>
47 EOT
48 return $html;
49 };
50
51 my $pjx = CGI::Ajax->new( 'multiply' => $multiply, 'divide' => $divide);
52 $pjx->JSDEBUG(1);
53 $pjx->DEBUG(1);
54 print $pjx->build_html($q,$Show_Form); # this outputs the html for the page