Mercurial > boosterpack
comparison scripts/pjx_cr.pl @ 0:477258d09353 boosterpack
[svn r1] initial import
author | robert |
---|---|
date | Sun, 30 Aug 2009 02:19:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:477258d09353 |
---|---|
1 #!C:/strawberry/perl/bin/perl.exe | |
2 | |
3 # this is an example script of how you would use coderefs to define | |
4 # your CGI::Ajax functions. | |
5 # | |
6 # NB The CGI::Ajax object must come AFTER the coderefs are declared. | |
7 | |
8 use strict; | |
9 use CGI::Ajax; | |
10 use CGI; | |
11 | |
12 my $q = new CGI; | |
13 | |
14 my $exported_fx = sub { | |
15 my $value_a = shift; | |
16 my $value_b = shift; | |
17 $value_a = "" if not defined $value_a; # make sure there's def | |
18 $value_b = "" if not defined $value_b; # make sure there's def | |
19 | |
20 if ( $value_a =~ /\D+/ or $value_a eq "" ) { | |
21 return( $value_a . " and " . $value_b ); | |
22 } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { | |
23 return( $value_a . " and " . $value_b ); | |
24 } else { | |
25 # got two numbers, so lets multiply them together | |
26 return( $value_a * $value_b ); | |
27 } | |
28 }; | |
29 | |
30 | |
31 my $Show_Form = sub { | |
32 my $html = ""; | |
33 $html .= <<EOT; | |
34 <HTML> | |
35 <HEAD><title>CGI::Ajax Example</title> | |
36 </HEAD> | |
37 <BODY> | |
38 <form> | |
39 Enter something: | |
40 <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] ); return true;"><br> | |
41 | |
42 Enter something else: | |
43 <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] ); return true;"><br> | |
44 | |
45 <hr> | |
46 <div id="resultdiv" style="border: 1px solid black; width: 440px; height: 80px; overflow: auto"> | |
47 </div> | |
48 </form> | |
49 </BODY> | |
50 </HTML> | |
51 EOT | |
52 | |
53 return $html; | |
54 }; | |
55 | |
56 my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx); | |
57 print $pjx->build_html($q,$Show_Form); # this outputs the html for the page |