On Dec 17, 2005, at 1:48 PM, Bruce McKenzie wrote:

There was a thread here in October with a request for an example of a simple implementation of CGI::App and Ajax. But then it went on and got a little too complicated -- at least I don't see any implementations simple enough for my skills in the followup posts :-) I'd particularly like to see something done with CGI::Ajax.pm, as I imagine it would be fairly easy to use that module. What I'd like to do, initially, is update a database without generating a new page.

Hi Bruce,

Did you try to get the example in the docs for CGI::Ajax running?

I'm including the example script I got running on my desktop below, hope it helps... After I got it running I played with Cees Hek's

"CGI-Application-Plugin-HTMLPrototype-0.20 - PodViewer Example"

It provides another approach and exercise to learn some AJAX stuff and I ended up keeping the demo just to use for reference sake.

Kindest Regards,

--
Bill Stephenson

<code>

#!/usr/bin/perl

use CGI::Ajax;
use CGI;
my $input;

my $cgi = new CGI();
my $pjx = new CGI::Ajax( 'evenodd' => \&evenodd_func );
print $pjx->build_html($cgi,\&Show_HTML);

sub evenodd_func {
  $input = shift;

  # see if input is defined
  if ( not defined $input ) {
    return("input not defined or NaN");
  }

  # see if value is a number (*thanks Randall!*)
  if ( $input !~ /\A\d+\z/ ) {
    return("input is NaN");
  }

  # got a number, so mod by 2
  $input % 2 == 0 ? return("EVEN") : return("ODD");
}


sub Show_HTML {
    my $html = qq~
  <HTML>
  <HEAD><title>CGI::Ajax Example</title>
  </HEAD>
  <BODY>
    Enter a number:&nbsp;
    <input type="text" name="somename" id="val1" size="6"
       onkeyup="evenodd( ['val1'], ['resultdiv'] ); return true;"><br>
    <hr>
    <div id="resultdiv">
    </div>
  </BODY>
  </HTML>
  ~;

    return $html;
  }

</code>


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/cgiapp@lists.erlbaum.net/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to