Thanks. I didn't have any trouble getting the dox examples running.

What has me flummoxed is getting an onClick event attached to a submit
button that will do what I want it to -- not submit the form, but rather
send the changed fields to an external perl script (run mode?) and
confirm that the changes were processed by the script without redrawing
the page. I think this probably isn't difficult, but I can't seem to sort out who does what, when and where.

Here's what I tried:


# run mode in WebApp.pm
sub display_test_form {
    my $self = shift;
    use CGI::Ajax;
    my $url = "handle_form.pl"; # A separate script to try            
                                # to simplify things;
    my $pjx = new CGI::Ajax( 'submit_formdata' => $url );
    my $ajax_js = $pjx->show_javascript();
    $self->tt_params(ajax_js=>$ajax_js);
    my $output = $self->tt_process('test_form.tt2');
    return $output;
}

// on the page generated by TTK (in addition to the javascript code
// generated by CGI::Ajax.pm

function doSubmit(){
   submit_formdata(['Bert'],['resultdiv']); //Bert is a text field
   return false;
}

and attached to the submit button:

onclick= doSubmit();
// doesn't work -- generates a "element has no properties"
// Javascript error

also tried the more obvious :

onclick = "submit_formdata(['Bert'],['resultdiv']);return false"

But that submits the damn form.

I was hoping just to get my feet wet -- HTML::Prototype looks kinda deep for a beginner :-)

Bruce


Bill Stephenson wrote:
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