annotate scripts/pjx_splitargs.pl @ 3:2e849c856026 boosterpack

[svn r5] it works!
author robert
date Tue, 08 Sep 2009 05:55:51 -0400
parents 477258d09353
children
rev   line source
robert@0 1 #!C:/strawberry/perl/bin/perl.exe
robert@0 2
robert@0 3 # this is an example script of how you would use coderefs to define
robert@0 4 # your CGI::Ajax functions, and the methods return multiple results to
robert@0 5 # the page
robert@0 6 #
robert@0 7 # NB The CGI::Ajax object must come AFTER the coderefs are declared.
robert@0 8
robert@0 9 use strict;
robert@0 10 use CGI::Ajax;
robert@0 11 use CGI;
robert@0 12
robert@0 13 my $q = new CGI;
robert@0 14
robert@0 15 my $divide = sub {
robert@0 16 my $a = shift;
robert@0 17 my $b = shift;
robert@0 18 return ($a / $b,"this is 2nd return value");
robert@0 19 };
robert@0 20
robert@0 21 my $Show_Form = sub {
robert@0 22 my $html = "";
robert@0 23 $html .= <<EOT;
robert@0 24 <HTML>
robert@0 25 <HEAD><title>CGI::Ajax Multiple Return Value Example</title>
robert@0 26 <script>
robert@0 27 my_call = function(){
robert@0 28 document.getElementById('out1').value = arguments[0];
robert@0 29 document.getElementById('out2').value = arguments[1];
robert@0 30 }
robert@0 31 </script>
robert@0 32 </HEAD>
robert@0 33 <BODY>
robert@0 34 <form>
robert@0 35 Enter Number:
robert@0 36 <input type="text" id="val1" size="6" value=2 onkeyup="divide(['val1','val2'], [my_call]);">
robert@0 37 <input type='text' id='val2' size=6 value=34 onkeyup="divide(['val1','val2'],[my_call]);">
robert@0 38
robert@0 39 <input type=text id="out1" value ="">
robert@0 40 <input type=text id="out2" value ="">
robert@0 41
robert@0 42
robert@0 43 </form>
robert@0 44 </BODY>
robert@0 45 </HTML>
robert@0 46 EOT
robert@0 47
robert@0 48 return $html;
robert@0 49 };
robert@0 50
robert@0 51 my $pjx = CGI::Ajax->new('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