view BoosterPack/scripts/.svn/text-base/pjx_subs.pl.svn-base @ 0:0d795f02a8bb tip

initial committ. what was I thinking?
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 16:57:26 -0400
parents
children
line wrap: on
line source
1 #!C:/strawberry/perl/bin/perl.exe
3 # this is an example of using subs (not coderefs) for your perljax
4 # functions
5 #
6 # NB The CGI::Ajax object DOES NOT need to follow the function
7 # declarations, as it does in the coderef example
9 use strict;
10 use CGI::Ajax;
11 use CGI;
13 my $q = new CGI;
14 my $pjx = CGI::Ajax->new( 'myfunc' => \&exported_fx);
15 print $pjx->build_html($q,\&Show_Form); # this outputs the html for the page
17 sub exported_fx {
18 my $value_a = shift;
19 my $value_b = shift;
20 $value_a = "" if not defined $value_a; # make sure there's def
21 $value_b = "" if not defined $value_b; # make sure there's def
23 if ( $value_a =~ /\D+/ or $value_a eq "" ) {
24 return( $value_a . " and " . $value_b );
25 } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) {
26 return( $value_a . " and " . $value_b );
27 } else {
28 # got two numbers, so lets multiply them together
29 return( $value_a * $value_b );
30 }
31 }
33 sub Show_Form {
34 my $html = "";
35 $html .= <<EOT;
36 <HTML>
37 <HEAD><title>CGI::Ajax Example</title>
38 </HEAD>
39 <BODY>
40 <form>
41 Enter something:&nbsp;
42 <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] );"><br>
44 Enter something else:&nbsp;
45 <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] );"><br>
47 <hr>
48 <div id="resultdiv" style="border: 1px solid black; width: 440px; height: 80px; overflow: auto">
49 </div>
50 </form>
51 </BODY>
52 </HTML>
53 EOT
54 return $html;
55 }