--- In Perl_Official@yahoogroups.com, "millerdw2003" <darren@...> wrote:
>
> Andy,
>
> I think the best way to accomplish what you're trying to do is to
> use AJAX. AJAX allows you to use JavaScript to issue an HTTP POST
> or GET without reloading the page. There's a perl module that makes
> this (relatively) easy to do at http://search.cpan.org/~bct/CGI-Ajax-
> 0.701/lib/CGI/Ajax.pm. The module includes several examples to get
> you started. If you're trying to anything very complicated, you'll
> need to read up on HTML, CGI, Javascript, and (less critically) XML.
>
> I'd recommend three books from O'Reilly and Associates (www.ora.com):
> * Programming Perl
> * JavaScript: the Definitive Guide 5th edition or later
> * CGI Programming with Perl
>
> The JavaScript book contains a whole chapter about AJAX that I found
> quite helpful.
>
> AJAX introduces significant additional complexity to your project --
> particularly if you haven't dealt with JavaScript much before. It
> might be easier to rethink the way your application works and decide
> if four independent forms on one page is worth the effort.
>
> Darren
>
> --- In Perl_Official@yahoogroups.com, "Andy Schafer"
> <lostgameparts@> wrote:
> >
> > Hi,
> >
> > I'm pretty new to Perl and need some help!
> >
> > I am working on a project that requires 4 forms on the same page. I
> > would like to be able to submit each one separately but if the user
> > has entered information in any of the other 3, that information
> will
> > be lost. (I think, and please correct me if I'm wrong!)
> >
> > What I'm wondering is this: Is there a way to submit a form to the
> CGI
> > script without actually leaving the page the form is on?
> >
> > I thought about using iFrames for each form but really don't like
> that
> > idea. I could also use one submit button for all 4 forms but I
> don't
> > like that either.
> >
> > I've hunted through all my books and on the net with no luck. I
> know
> > I'm probably overlooking something simple but I can't for the life
> of
> > me find it!
> >
> > If any of you can help me I would really appreciate it!
> >
> > Thank you very much!
> > Andy
> >
>
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
our $q=new CGI;
our ($firstNumber,$secondNumber);
# This perl script calls itself and posts variables back to itself.
our $thisURL =$q->self_url;
our %data; #hash to store cgi params
foreach my $name ($q-> param() )
{
$data{$name} = param($name);
}
# Get the path values from the query string
if (exists $data{firstNumber}) { $firstNumber=$data{firstNumber};}
else {$firstNumber=0;}
if (exists $data{secondNumber}) {$secondNumber=$data{secondNumber};}
else {$secondNumber=0;}
print $q->header('text/html');
&page1;
&sumsNprint; #do sums and print
print "</b></body>\n </html>\n";
#-------------------------------------------------------------------------------\
-------------------
sub page1 # print the HTML stuff
{
print "
<html>
<head><TITLE>Mt page</TITLE>
</head>
<body leftmargin='20' marginwidth='10' bgcolor='#FFFFFF'>
<b>
<font face='Verdana,Arial,Helvetica,sans-serif'>
<H2> My page</H2>
Please fill out the following information and press the CALCULATE
button<BR>
</h4>
<form method='GET' action=$thisURL>
<TABLE BORDER=2 FRAME=box CELLPADDING=1 CELLSPACING=0>
<TR>
<TD><B><h5>First number</B>
<INPUT NAME='firstNumber' TYPE='text' SIZE='10'
VALUE=$firstNumber><BR></TD>
</TR>
<TR>
<TD><B><h5>Second Number</B>
<INPUT NAME='secondNumber' TYPE='text' SIZE='10'
VALUE=$secondNumber><BR></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE='submit' VALUE='CALCULATE'></FORM>
";
}
sub sumsNprint
{
my $result=$firstNumber * $secondNumber;
print "$firstNumber times $secondNumber = $result<BR>\n"
}