diff scripts/pjx_callback.pl @ 0:477258d09353 boosterpack

[svn r1] initial import
author robert
date Sun, 30 Aug 2009 02:19:26 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/pjx_callback.pl	Sun Aug 30 02:19:26 2009 -0400
     1.3 @@ -0,0 +1,68 @@
     1.4 +#!C:/strawberry/perl/bin/perl.exe
     1.5 +
     1.6 +# this is an example script of how you would use coderefs to define
     1.7 +# your CGI::Ajax functions, and the methods return multiple results to
     1.8 +# the page
     1.9 +#
    1.10 +# NB The CGI::Ajax object must come AFTER the coderefs are declared.
    1.11 +
    1.12 +use strict;
    1.13 +use CGI::Ajax;
    1.14 +use CGI;
    1.15 +
    1.16 +my $q = new CGI;
    1.17 +
    1.18 +my $multiply = sub {
    1.19 +  my $a = shift;
    1.20 +  my $b = shift;
    1.21 +  return $a * $b;
    1.22 +};
    1.23 +
    1.24 +my $divide = sub {
    1.25 +  my $a = shift;
    1.26 +  my $b = shift;
    1.27 +  return $a / $b;
    1.28 +};
    1.29 +my $G = 'asdf';
    1.30 +my $Show_Form = sub {
    1.31 +  my $html = "";
    1.32 +  $html .= qq!
    1.33 +<HTML>
    1.34 +<HEAD><title>CGI::Ajax Multiple Return Value Example</title>
    1.35 +<script>
    1.36 +  my_call = function(){
    1.37 +   document.getElementById('out1').value = arguments[0];
    1.38 +   call_2();
    1.39 +   document.getElementById('out3').innerHTML = this.url;
    1.40 +  }
    1.41 +  call_2 =function(){
    1.42 +   multiply(['val1','val2'],['out2'],'POST');
    1.43 +  }
    1.44 +
    1.45 +</script>
    1.46 +</HEAD>
    1.47 +<BODY>
    1.48 +<form>
    1.49 +  Enter Number:
    1.50 +<input type="text" id="val1" size="6" value=2 
    1.51 +    onkeyup="divide(['val1','val2','args__$G'], [my_call], 'POST');">
    1.52 +<input type='text' id='val2' size=6 value=34>
    1.53 +
    1.54 +<input type=text id="out1">
    1.55 +<input type=text id="out2"><br/>
    1.56 +URL FROM "this" in callback:<div id="out3"> </div>
    1.57 +
    1.58 +
    1.59 +</form>
    1.60 +</BODY>
    1.61 +</HTML>
    1.62 +!;
    1.63 +
    1.64 +  return $html;
    1.65 +};
    1.66 +
    1.67 +
    1.68 +my $pjx = CGI::Ajax->new( 'multiply' => $multiply, 'divide' => $divide);
    1.69 +$pjx->JSDEBUG(1);
    1.70 +$pjx->DEBUG(1);
    1.71 +print $pjx->build_html($q,$Show_Form); # this outputs the html for the page