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