tantric
02-19-2007, 11:52 PM
It seems the specific boards for this are down. I can't get multiple returns to work, even though my script almost mimics the example. This really should make the same message appear in the first div as in the table div....Anyway, it's also utterly HTML and Jscript free Ajax, for what that's worth.
#! /usr/bin/perl -w
use CGI::Ajax;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use DBI;
$cgi = new CGI;
my $Show_Form = sub {
my $dBopts=["primates", "rodents", "ungulates", "carnivores"];
my @html =($cgi->header(-type=>"text/javascript" -src=>"binding.js"),
$cgi->start_html(-title=>'GDET Intro Page'),
$cgi->center($cgi->h3("GMPD Data Entry Tool Introduction")),$cgi->p,
$cgi->h3("Please select a database"),
$cgi->startform(-name=>'Select1', -method=>'POST'),
"User Name :",
$cgi->textfield(-name=>'user', -id=>"user"),
"Password :",
$cgi->password_field(-name=>'password', -id=>"password"),
"Database :",
$cgi->popup_menu(-id=>"Database", -name=>"Database", -value=>$dBopts, -width=>'1'),
$cgi->button(-name=>"SelectdB", -value=>"SelectdB", -onClick=>"connectdB( ['Database', 'user', 'password'], ['div3', 'newref']); return true;"),$cgi->p);
$html=join("\n", @html);
my @boxhtml=($cgi->h4("Connection status:"),
$cgi->div({-id=>"div3"}),
$cgi->end_div(-id=>"div3"));
my $boxhtml=join("\n", @boxhtml);
$html .= $boxhtml;
my $cellhtml=join("\n", ($cgi->div({-id=>'newref', -style=>'width: 200px;
height: 20px; overflow: auto'}), $cgi->end_div({-id=>'newref'})));
my @formhtml=($cgi->startform(-name=>'Select2', -method=>'POST'),
$cgi->table({-border=>'2', -width=>"50%"},
$cgi->Tr({-align=>"LEFT",-valign=>"TOP"},
$cgi->td(["References"]),
$cgi->td([$cgi->center($cgi->submit(-name=>'New Reference', -value=>'New Reference', -onClick=>"document.fork1.action='GDETNewRef.cgi';"))], -colspan=>1),
$cgi->td([$cellhtml], -colspan=>2))));
$html .= join("\n", @formhtml);
my $endhtml = join("\n", ($cgi->endform, $cgi->end_html));
$html .= $endhtml;
return ($html);
};
#
my $connectdB=sub
{
my $dB=shift;
my $user=shift;
my $password=shift;
# $cgi->param("dBprefix")="Ung" if($db eq "ungulates");
# $cgi->param("dBprefix")="Sqrl" if($db eq "rodents");
# $cgi->param("dBprefix")="Carn" if($db eq "carnivores");
# $cgi->param("dBprefix")="Prim" if($db eq "primates");
my $connectstring=join(":", "DBI", "mysql", $dB, "128.192.18.43:3306");
my %dBattr = (
PrintError => 0,
RaiseError => 0
);
my $dbh = DBI->connect($connectstring, $user, $password, \%dBattr) or $html=join("\n", ($cgi->h3($dbh->errstr())));
my $html=join("\n", ($cgi->h6("connected to $dB as $user"))) if(!$html);
my $dupe=join("\n", $cgi->h6("connected!!!"));
return($dupe, $html);
};
my $pjx = CGI::Ajax->new( connectdB => $connectdB);
$pjx->JSDEBUG(1);
$pjx->DEBUG(1);
# not show the html, which will include the embedded javascript code
# to handle the ajax interaction
print $pjx->build_html($cgi,$Show_Form); # this outputs the html for the page
#print $Show_Form;
#! /usr/bin/perl -w
use CGI::Ajax;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use DBI;
$cgi = new CGI;
my $Show_Form = sub {
my $dBopts=["primates", "rodents", "ungulates", "carnivores"];
my @html =($cgi->header(-type=>"text/javascript" -src=>"binding.js"),
$cgi->start_html(-title=>'GDET Intro Page'),
$cgi->center($cgi->h3("GMPD Data Entry Tool Introduction")),$cgi->p,
$cgi->h3("Please select a database"),
$cgi->startform(-name=>'Select1', -method=>'POST'),
"User Name :",
$cgi->textfield(-name=>'user', -id=>"user"),
"Password :",
$cgi->password_field(-name=>'password', -id=>"password"),
"Database :",
$cgi->popup_menu(-id=>"Database", -name=>"Database", -value=>$dBopts, -width=>'1'),
$cgi->button(-name=>"SelectdB", -value=>"SelectdB", -onClick=>"connectdB( ['Database', 'user', 'password'], ['div3', 'newref']); return true;"),$cgi->p);
$html=join("\n", @html);
my @boxhtml=($cgi->h4("Connection status:"),
$cgi->div({-id=>"div3"}),
$cgi->end_div(-id=>"div3"));
my $boxhtml=join("\n", @boxhtml);
$html .= $boxhtml;
my $cellhtml=join("\n", ($cgi->div({-id=>'newref', -style=>'width: 200px;
height: 20px; overflow: auto'}), $cgi->end_div({-id=>'newref'})));
my @formhtml=($cgi->startform(-name=>'Select2', -method=>'POST'),
$cgi->table({-border=>'2', -width=>"50%"},
$cgi->Tr({-align=>"LEFT",-valign=>"TOP"},
$cgi->td(["References"]),
$cgi->td([$cgi->center($cgi->submit(-name=>'New Reference', -value=>'New Reference', -onClick=>"document.fork1.action='GDETNewRef.cgi';"))], -colspan=>1),
$cgi->td([$cellhtml], -colspan=>2))));
$html .= join("\n", @formhtml);
my $endhtml = join("\n", ($cgi->endform, $cgi->end_html));
$html .= $endhtml;
return ($html);
};
#
my $connectdB=sub
{
my $dB=shift;
my $user=shift;
my $password=shift;
# $cgi->param("dBprefix")="Ung" if($db eq "ungulates");
# $cgi->param("dBprefix")="Sqrl" if($db eq "rodents");
# $cgi->param("dBprefix")="Carn" if($db eq "carnivores");
# $cgi->param("dBprefix")="Prim" if($db eq "primates");
my $connectstring=join(":", "DBI", "mysql", $dB, "128.192.18.43:3306");
my %dBattr = (
PrintError => 0,
RaiseError => 0
);
my $dbh = DBI->connect($connectstring, $user, $password, \%dBattr) or $html=join("\n", ($cgi->h3($dbh->errstr())));
my $html=join("\n", ($cgi->h6("connected to $dB as $user"))) if(!$html);
my $dupe=join("\n", $cgi->h6("connected!!!"));
return($dupe, $html);
};
my $pjx = CGI::Ajax->new( connectdB => $connectdB);
$pjx->JSDEBUG(1);
$pjx->DEBUG(1);
# not show the html, which will include the embedded javascript code
# to handle the ajax interaction
print $pjx->build_html($cgi,$Show_Form); # this outputs the html for the page
#print $Show_Form;