view scripts/pjx_subs.pl @ 6:4246c7ef6487 boosterpack

[svn r8] bug fix -- holos need to be one int three compared to rares
author robert
date Tue, 08 Sep 2009 17:20:52 -0400
parents 477258d09353
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 }