> > Hi
> >
> > I'm using HTML form to execute a .cgi script and I want the output of
> cgi script should display in the same
> > window in which Form is displayed.
> >
> > Anyone can suggest that how to do it.
>
> I would have thought that the simplest way would be for the cgi program
> to output both the form, and when data is entered on the form, the
> output as well.
>
> This isn't really a Perl question, but as this is a Perl forum here is a
> simplistic example of what I mean.
>
This will get you started in Ajax. Go to
http://www.biblescramble.com/samcod/use2PHPs.html to see this in action.
Here is the content of subber.cgi:
####
#!/usr/bin/perl
use CGI qw/:standard/;
use CGI::Carp qw(carpout fatalsToBrowser);
$result=subway(109, 2, 5, "babies", "dogs");
print header,
start_html(-title=>"Subber"),
style("p.comment {font-size: 50%}
#p {font-size: 150%; margin-left: 5.5cm; margin-right: 5.5cm}
br {font-size: 150%; margin-left: 5.5cm; margin-right: 5.5cm}
h1 {margin-left: 3.5cm}
#h2 {margin-left: 4.5cm}
body {background: #218f99; font-family: cursive; }"),
h4("$result"),
end_html;
sub subway()
{
$bigNum=shift;
pop;
$littleNum=shift;
$noun=pop;
$x=$bigNum*$littleNum;
$final="$x $noun";
}
####
Here is the content of use2PHPs.html:
####
<html><head><title>Use Two Aj ax Calls</title>
<script>
function ajax(file)
{
if(window.XMLHttpRequest)
{
jax = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
jax = new ActiveXObject("Microsoft.XMLHTTP");
}
if(jax)
{
jax.open("POST", file);
jax.onreadystatechange = function()
{
if(jax.readyState == 4)
{
document.getElementById("output").innerHTML =
jax.responseText;
}
}
jax.send(null);
}
else
{
alert("Contact site owner for ajax alternative.");
}
}
</script></head>
<body>
<input type = "button" value = "Run use2PHPs.php" onClick =
ajax('use2PHPs.php'); return true;><p>
<input type = "button" value = "Run use2PHP.php" onClick =
ajax('use2PHP.php'); return true;><p>
<input type = "button" value = "Bonus: Run subber.cgi!" onClick =
ajax('subber.cgi'); return true;>
<div id = "output"></div>
</body></html>
####
I don't know how this all will strike you, so I haven't put a lot of time into
making it presentable for the public. If you want any explanations, like how to
use javaScript innerHTML to get what is sent back to the html into a variable,
let me know.
Jerry Kassebaum
Dallas, TX
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
http://clk.atdmt.com/GBL/go/171222985/direct/01/
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs