diff scripts/pjx_manyret.pl @ 0:477258d09353 boosterpack

[svn r1] initial import
author robert
date Sun, 30 Aug 2009 02:19:26 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/pjx_manyret.pl	Sun Aug 30 02:19:26 2009 -0400
     1.3 @@ -0,0 +1,75 @@
     1.4 +#!C:/strawberry/perl/bin/perl.exe
     1.5 +
     1.6 +# this is an example script of how you would use coderefs to define
     1.7 +# your CGI::Ajax functions, and the methods return multiple results to
     1.8 +# the page
     1.9 +#
    1.10 +# NB The CGI::Ajax object must come AFTER the coderefs are declared.
    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 +
    1.18 +my $exported_fx = sub {
    1.19 +  my $value_a = shift;
    1.20 +  my $value_b = shift;
    1.21 +  $value_a = "" if not defined $value_a; # make sure there's def
    1.22 +  $value_b = "" if not defined $value_b; # make sure there's def
    1.23 +
    1.24 +  if ( $value_a =~ /\D+/ or $value_a eq "" ) {
    1.25 +    return( $value_a, $value_b, 'NaN' );
    1.26 +  } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) {
    1.27 +    return( $value_a, $value_b, 'NaN' );
    1.28 +  } else {
    1.29 +    # got two numbers, so lets multiply them together
    1.30 +    return( $value_a, $value_b, $value_a * $value_b );
    1.31 +  }
    1.32 +};
    1.33 +
    1.34 +
    1.35 +my $Show_Form = sub {
    1.36 +  my $html = "";
    1.37 +  $html .= <<EOT;
    1.38 +<HTML>
    1.39 +<HEAD><title>CGI::Ajax Multiple Return Value Example</title>
    1.40 +</HEAD>
    1.41 +<BODY>
    1.42 +<form>
    1.43 +  Enter something:&nbsp;
    1.44 +  <input type="text" name="val1" id="val1" size="6" onkeyup="myfunc( ['val1','val2'], ['inputa','inputb','resultdiv'] ); return true;"><br>
    1.45 +
    1.46 +  Enter something else:&nbsp;
    1.47 +  <input type="text" name="val2" id="val2" size="6" onkeyup="myfunc( ['val1','val2'], ['inputa','inputb','resultdiv'] ); return true;"><br>
    1.48 +
    1.49 +    <hr>
    1.50 +    <table>
    1.51 +      <tr>
    1.52 +        <td>Input A</td>
    1.53 +        <td>Input B</td>
    1.54 +        <td>Result</td>
    1.55 +      </tr>
    1.56 +      <tr>
    1.57 +        <td>
    1.58 +          <div id="inputa" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div>
    1.59 +        </td>
    1.60 +        <td>
    1.61 +          <div id="inputb" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div>
    1.62 +        </td>
    1.63 +        <td>
    1.64 +          <div id="resultdiv" style="text-align: center; border: 1px solid black; width: 80px; height: 20px; overflow: auto"></div>
    1.65 +        </td>
    1.66 +      </tr>
    1.67 +    </table>
    1.68 +</form>
    1.69 +</BODY>
    1.70 +</HTML>
    1.71 +EOT
    1.72 +
    1.73 +  return $html;
    1.74 +};
    1.75 +
    1.76 +my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx);
    1.77 +$pjx->JSDEBUG(1);
    1.78 +print $pjx->build_html($q,$Show_Form); # this outputs the html for the page