view scripts/pjx_chained.pl @ 10:3b52ac950753 boosterpack tip

going to try to fix this thing
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 17:24:06 -0400
parents 477258d09353
children
line wrap: on
line source
1 #!C:/strawberry/perl/bin/perl.exe
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']);"
7 use strict;
8 use CGI::Ajax;
9 use CGI;
11 my $q = new CGI;
13 my $multiply = sub {
14 my $a = shift;
15 my $b = shift;
16 return $a * $b;
17 };
19 my $divide = sub {
20 my $a = shift;
21 my $b = shift;
22 return $a / $b;
23 };
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']);">
37 <input type="text" id="val2" size="6" value = 7
38 onkeyup="divide(['val1','val2'], ['out1']); multiply(['val1','val2'], ['out2']);"><br/><br/>
40 <input type=text id="out1">
41 <input type=text id="out2">
44 </form>
45 </BODY>
46 </HTML>
47 EOT
48 return $html;
49 };
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