annotate scripts/pjx_subs.pl @ 7:4c495190076f boosterpack

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