Mercurial > boosterpack
comparison scripts/pjx_callback.pl @ 0:477258d09353 boosterpack
[svn r1] initial import
author | robert |
---|---|
date | Sun, 30 Aug 2009 02:19:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:477258d09353 |
---|---|
1 #!C:/strawberry/perl/bin/perl.exe | |
2 | |
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. | |
8 | |
9 use strict; | |
10 use CGI::Ajax; | |
11 use CGI; | |
12 | |
13 my $q = new CGI; | |
14 | |
15 my $multiply = sub { | |
16 my $a = shift; | |
17 my $b = shift; | |
18 return $a * $b; | |
19 }; | |
20 | |
21 my $divide = sub { | |
22 my $a = shift; | |
23 my $b = shift; | |
24 return $a / $b; | |
25 }; | |
26 my $G = 'asdf'; | |
27 my $Show_Form = sub { | |
28 my $html = ""; | |
29 $html .= qq! | |
30 <HTML> | |
31 <HEAD><title>CGI::Ajax Multiple Return Value Example</title> | |
32 <script> | |
33 my_call = function(){ | |
34 document.getElementById('out1').value = arguments[0]; | |
35 call_2(); | |
36 document.getElementById('out3').innerHTML = this.url; | |
37 } | |
38 call_2 =function(){ | |
39 multiply(['val1','val2'],['out2'],'POST'); | |
40 } | |
41 | |
42 </script> | |
43 </HEAD> | |
44 <BODY> | |
45 <form> | |
46 Enter Number: | |
47 <input type="text" id="val1" size="6" value=2 | |
48 onkeyup="divide(['val1','val2','args__$G'], [my_call], 'POST');"> | |
49 <input type='text' id='val2' size=6 value=34> | |
50 | |
51 <input type=text id="out1"> | |
52 <input type=text id="out2"><br/> | |
53 URL FROM "this" in callback:<div id="out3"> </div> | |
54 | |
55 | |
56 </form> | |
57 </BODY> | |
58 </HTML> | |
59 !; | |
60 | |
61 return $html; | |
62 }; | |
63 | |
64 | |
65 my $pjx = CGI::Ajax->new( 'multiply' => $multiply, 'divide' => $divide); | |
66 $pjx->JSDEBUG(1); | |
67 $pjx->DEBUG(1); | |
68 print $pjx->build_html($q,$Show_Form); # this outputs the html for the page |