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