Please enter your name:
Please enter a value for x:
Please enter a value for y:
Select from the following Operations:
+ - * /
This functionality is accomplished by the following HTML code:
<HTML><HEAD><TITLE>CGI Test</TITLE></HEAD>
<CENTER><H1><U>CGI Test</U></H1></CENTER>
<CENTER><H3>by Brandon Cantillo</H3></CENTER>
<html>
<body>
<form action="form.cgi"> // This calls the CGI file to implement the active functionality using PERL
<PRE>Please enter your name:</PRE>
<input type="text" name="name"></input>
<PRE>Please enter a value for x:</PRE>
<input type="text" name="xval" size=1></input>
<PRE>Please enter a value for y:</PRE>
<input type="text" name="yval" size=1></input>
<br>
<PRE>Select from the following Operations:</PRE>
<input type="radio" name="operation" value="+" size=1></input>
+
<input type="radio" name="operation" value="-" size=1></input>
-
<input type="radio" name="operation" value="*" size=1></input>
*
<input type="radio" name="operation" value="/" size=1></input>
/
<HR>
<input type="submit" name="submit" value="submit"></input>
</form>
</body>
</html>
It then calls the following PERL code:
#!/usr/bin/perl
#
use CGI qw(param);
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html\n";
$header .= "\n";
#get the parameter "fname"
$name1 = param("name");
$xval = param("xval");
$yval = param("yval");
$operation = param("operation");
#get the current time
$time = scalar localtime;
#must print in HTML form to ensure proper formatting.
print "$header<h1>Hello, $name1 ! How are you today?</h1><br>The time is: $time";
print "<br>";
print "\n","X = $xval";
print "\n","Y = $yval";
if ($operation eq "+")
{
print "\n","X plus Y is ",$xval+$yval,".";
}
if ($operation eq "-")
print "\n","X minus Y is ",$xval-$yval,".";
if ($operation eq "*")
print "\n","X times Y is ",$xval*$yval,".";
if ($operation eq "/")
print "\n","X divided by Y is ",$xval/$yval,".";