Mercurial > boosterpack
view scripts/pjx_podex.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.exe2 use strict;3 use CGI::Ajax;4 use CGI;6 # define an anonymous perl subroutine that you want available to7 # javascript on the generated web page.9 my $evenodd_func = sub {10 my $input = shift;12 my $magic = " <font size=-1>look ma, no submit!</font><br>";14 # see if input is defined15 if ( not defined $input ) {16 return("input not defined or NaN" . $magic);17 }19 # see if value is a number (*thanks Randall!*)20 if ( $input !~ /\A\d+\z/ ) {21 return("input is NaN" . $magic);22 }24 # got a number, so mod by 225 $input % 2 == 0 ? return("$input is EVEN" . $magic) : return("$input is ODD" . $magic);27 }; # don't forget the trailing ';', since this is an anon subroutine29 # define a function to generate the web page - this can be done30 # million different ways, and can also be defined as an anonymous sub.31 # The only requirement is that the sub send back the html of the page.32 sub Show_HTML {33 my $html = "";34 $html .= <<EOT;36 <HTML>37 <HEAD><title>CGI::Ajax Example</title>38 </HEAD>39 <BODY>40 <form>41 Enter a number: 42 <input type="text" name="val1" id="val1" size="6"43 onkeyup="evenodd( ['val1'], ['resultdiv'] ); return true;"><br>44 <hr>45 <div id="resultdiv" style="border: 1px solid black;46 width: 440px; height: 80px; overflow: auto">47 </div>48 </form>49 </BODY>50 </HTML>51 EOT53 return $html;54 }56 my $cgi = new CGI(); # create a new CGI object57 # now we create a CGI::Ajax object, and associate our anon code58 my $pjx = new CGI::Ajax( 'evenodd' => $evenodd_func );60 # now print the page. This can be done easily using61 # CGI::Ajax->build_html, sending in the CGI object to generate the html62 # header. This could also be done manually, and then you don't need63 # the build_html() method64 print $pjx->build_html($cgi,\&Show_HTML); # this outputs the html for the page66 # that's it!