view BoosterPack/scripts/.svn/text-base/pjx_callback.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
line wrap: on
line source
1 #!C:/strawberry/perl/bin/perl.exe
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.
9 use strict;
10 use CGI::Ajax;
11 use CGI;
13 my $q = new CGI;
15 my $multiply = sub {
16 my $a = shift;
17 my $b = shift;
18 return $a * $b;
19 };
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 }
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>
51 <input type=text id="out1">
52 <input type=text id="out2"><br/>
53 URL FROM "this" in callback:<div id="out3"> </div>
56 </form>
57 </BODY>
58 </HTML>
59 !;
61 return $html;
62 };
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