Mercurial > boosterpack
diff scripts/pjx_chained.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_chained.pl Sun Aug 30 02:19:26 2009 -0400 1.3 @@ -0,0 +1,54 @@ 1.4 +#!C:/strawberry/perl/bin/perl.exe 1.5 + 1.6 +# pjx_chained.pl: Multiple exported perl subs, and the exported 1.7 +# functions are chained to an event, like this... 1.8 +# onclick="func1(['in1'],['out1']); func2(['in1'],['out2']);" 1.9 + 1.10 +use strict; 1.11 +use CGI::Ajax; 1.12 +use CGI; 1.13 + 1.14 +my $q = new CGI; 1.15 + 1.16 +my $multiply = sub { 1.17 + my $a = shift; 1.18 + my $b = shift; 1.19 + return $a * $b; 1.20 +}; 1.21 + 1.22 +my $divide = sub { 1.23 + my $a = shift; 1.24 + my $b = shift; 1.25 + return $a / $b; 1.26 +}; 1.27 + 1.28 +my $Show_Form = sub { 1.29 + my $html = ""; 1.30 + $html .= <<EOT; 1.31 +<HTML> 1.32 +<HEAD><title>CGI::Ajax Chained function Example</title> 1.33 +</HEAD> 1.34 +<BODY> 1.35 +<form> 1.36 + Enter Number: 1.37 +<input type="text" id="val1" size="6" value=2 1.38 + onkeyup="divide(['val1','val2'], ['out1']); multiply(['val1','val2'], ['out2']);"> 1.39 + 1.40 +<input type="text" id="val2" size="6" value = 7 1.41 + onkeyup="divide(['val1','val2'], ['out1']); multiply(['val1','val2'], ['out2']);"><br/><br/> 1.42 + 1.43 +<input type=text id="out1"> 1.44 +<input type=text id="out2"> 1.45 + 1.46 + 1.47 +</form> 1.48 +</BODY> 1.49 +</HTML> 1.50 +EOT 1.51 + return $html; 1.52 +}; 1.53 + 1.54 +my $pjx = CGI::Ajax->new( 'multiply' => $multiply, 'divide' => $divide); 1.55 +$pjx->JSDEBUG(1); 1.56 +$pjx->DEBUG(1); 1.57 +print $pjx->build_html($q,$Show_Form); # this outputs the html for the page