In the following code, I want to sum the MideTerm, Project and the Final and write the value in the textbox of Total automatically. I wrote a javascript code but it didn't work.
<html>
<head>
[COLOR="red"]<SCRIPT>
function addThreeNums (inOne, inTwo, inThree) {
var inOne = Number(inOne);
var inTwo = Number(inTwo);
var inThree = Number(inThree);
return Number(inOne + inTwo + inThree);
}
</SCRIPT>
[/COLOR]</head>
<body>
<title>Num One Website</title>
<?
$con = mysql_connect("mysql17.000webhost.com","a6395791_nasser","11a12a13a");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("a6395791_StMarks", $con);
$result1 = mysql_query("SELECT * FROM Students") ;
$count=1;
echo "<form action='ConfirmEnter.php' method='post'>";
echo "<form name= 'theForm'>";
echo "<table border cellpadding=3>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>MidTerm</th>";
echo "<th>Project</th>";
echo "<th>Final</th>";
echo "<th>Total</th>". "</tr>";
while($row1 = mysql_fetch_array($result1))
{
echo "<tr>";
echo "<td><input name='ID' readonly='readonly' value='". $row1['ID'] ."' size=5/></td> ";
echo "<td><input type='text' name='mt' size=5 value='0.0'/></td>";
echo "<td><input type='text' name='pr' size=5 value='0.0' /></td>";
echo "<td><input type='text' name='fi' size=5 value='0.0' /></td>";
[COLOR="red"]echo "<td><input type='text' name='tot' size=5 value='document.write(addThreeNums(theForm.mt.value,theForm.pr.value,theForm.fi.value));' /></td>";
[/COLOR] echo "</tr>";
}
echo "</table>";
echo "<input type='submit' value='Submit' />";
echo "</form>";
echo "</form>";
mysql_close($con);
?>
</body>
</html>
Thank you


Sign In
Create Account

Back to top









