view scripts/pjx_cr.pl @ 10:3b52ac950753 boosterpack tip

going to try to fix this thing
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 17:24:06 -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.
5 #
6 # NB The CGI::Ajax object must come AFTER the coderefs are declared.
8 use strict;
9 use CGI::Ajax;
10 use CGI;
12 my $q = new CGI;
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
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 };
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:&nbsp;
40 <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] ); return true;"><br>
42 Enter something else:&nbsp;
43 <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] ); return true;"><br>
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
53 return $html;
54 };
56 my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx);
57 print $pjx->build_html($q,$Show_Form); # this outputs the html for the page