diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/BoosterPack/scripts/.svn/text-base/pjx_subs.pl.svn-base	Mon Sep 27 16:57:26 2010 -0400
     1.3 @@ -0,0 +1,55 @@
     1.4 +#!C:/strawberry/perl/bin/perl.exe
     1.5 +
     1.6 +# this is an example of using subs (not coderefs) for your perljax
     1.7 +# functions
     1.8 +#
     1.9 +# NB The CGI::Ajax object DOES NOT need to follow the function
    1.10 +# declarations, as it does in the coderef example
    1.11 +
    1.12 +use strict;
    1.13 +use CGI::Ajax;
    1.14 +use CGI;
    1.15 +
    1.16 +my $q = new CGI;
    1.17 +my $pjx = CGI::Ajax->new( 'myfunc' => \&exported_fx);
    1.18 +print $pjx->build_html($q,\&Show_Form); # this outputs the html for the page
    1.19 +
    1.20 +sub exported_fx {
    1.21 +  my $value_a = shift;
    1.22 +  my $value_b = shift;
    1.23 +  $value_a = "" if not defined $value_a; # make sure there's def
    1.24 +  $value_b = "" if not defined $value_b; # make sure there's def
    1.25 +
    1.26 +  if ( $value_a =~ /\D+/ or $value_a eq "" ) {
    1.27 +    return( $value_a . " and " . $value_b );
    1.28 +  } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) {
    1.29 +    return( $value_a . " and " . $value_b );
    1.30 +  } else {
    1.31 +    # got two numbers, so lets multiply them together
    1.32 +    return( $value_a * $value_b );
    1.33 +  }
    1.34 +}
    1.35 +
    1.36 +sub Show_Form {
    1.37 +  my $html = "";
    1.38 +  $html .= <<EOT;
    1.39 +<HTML>
    1.40 +<HEAD><title>CGI::Ajax Example</title>
    1.41 +</HEAD>
    1.42 +<BODY>
    1.43 +<form>
    1.44 +  Enter something:&nbsp;
    1.45 +  <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] );"><br>
    1.46 +
    1.47 +  Enter something else:&nbsp;
    1.48 +  <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['resultdiv'] );"><br>
    1.49 +
    1.50 +    <hr>
    1.51 +    <div id="resultdiv" style="border: 1px solid black; width: 440px; height: 80px; overflow: auto">
    1.52 +    </div>
    1.53 +</form>
    1.54 +</BODY>
    1.55 +</HTML>
    1.56 +EOT
    1.57 +  return $html;
    1.58 +}