view scripts/pjx_splitargs.pl @ 9:9652dc713ba6 boosterpack

working on adding to rlmcintyre.com
author Robert McIntyre <rlm@mit.edu>
date Sat, 26 Jun 2010 20:06:08 -0400
parents 477258d09353
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 $divide = sub {
16 my $a = shift;
17 my $b = shift;
18 return ($a / $b,"this is 2nd return value");
19 };
21 my $Show_Form = sub {
22 my $html = "";
23 $html .= <<EOT;
24 <HTML>
25 <HEAD><title>CGI::Ajax Multiple Return Value Example</title>
26 <script>
27 my_call = function(){
28 document.getElementById('out1').value = arguments[0];
29 document.getElementById('out2').value = arguments[1];
30 }
31 </script>
32 </HEAD>
33 <BODY>
34 <form>
35 Enter Number:
36 <input type="text" id="val1" size="6" value=2 onkeyup="divide(['val1','val2'], [my_call]);">
37 <input type='text' id='val2' size=6 value=34 onkeyup="divide(['val1','val2'],[my_call]);">
39 <input type=text id="out1" value ="">
40 <input type=text id="out2" value ="">
43 </form>
44 </BODY>
45 </HTML>
46 EOT
48 return $html;
49 };
51 my $pjx = CGI::Ajax->new('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