I want a table that is auto computing like the ability of the microsoft excel that when I input a data in cell B1, C1 and D1( just an example on the features of excel ) it will compute an average in cell E1 which does not need to press any button to compute and tells whether if it is passing, passed or failed in cell F1( this cell f1 designates from the computation )

my aim here is to input 20 persons and input the Prelim Grade, Midterm Grade and Final Grade then the average is shown on the next cell(auto computed) then tells the equivalence of the average for example is: if the average is greater than 90 it will show the grade equivalence of 90. if it is 85 the equivalence is 1.50. if the average is 75 it will show 3.00 and if it is below 75... it will show an equivalence of 5.00

here is my scratch code

<html>
<title>grades</title>
<body bgcolor=red>
<form method=post>
<?php
echo"<table><tr><td>Name:</td><td>prelim grade</td><td>midterm grade</td><td>final grade</td><td>equivalent</td><td>Remarks</td></tr><tr><td><input type=text name=name1></td>
<td><input type=text name=name2></td><td><input type=text name=name3></td><td><input type=text name=name4></td><td><input type=text name=name5></td><tr><td>";
$ave=($_POST['name2']+$_POST['name3']+$_POST['name4'])/3;
echo"$ave<br>";
if($ave==75){
echo "passing";
}elseif($ave>76){
echo "passed";
}else
echo "failed";
?><br>
<input type=submit value=compute></body></html>

i need to auto compute the table

I would use javascript to calculate the values, all you need is and id in the <td> where you want the avg to be then an onkeypress="javascript: updateAvg();" on each of your names. In the function:

function updateAvg(){
var avg;
avg = (document.getElementById('name1').value + document.getElementById('name2').value + document.getElementById('name3').value)/3;
document.getElementById('[id of the <td>]').innerHTML = avg;
}

Something simple like that should do it. Of course you'll need id tags instead of name tags.

<html><title>grades</title><body bgcolor=red><form method=post><?phpecho"<table><tr><td>Name:</td><td>prelim grade</td><td>midterm grade</td><td>final grade</td><td>equivalent</td><td>Remarks</td></tr><tr><td><input type=text name=name1></td><td><input type=text name=name2></td><td><input type=text name=name3></td><td><input type=text name=name4></td><td><input type=text name=name5></td><tr><td>";$ave=($_POST['name2']+$_POST['name3']+$_POST['name4'])/3;echo"$ave<br>";if($ave==75){echo "passing";}elseif($ave>76){echo "passed";}elseecho "failed";?><br><input type=submit value=compute></body></html><html>
<title>grades</title>
<body bgcolor=red>
<form method=post>
<?php
echo"<table><tr><td>Name:</td><td>prelim grade</td><td>midterm grade</td><td>final grade</td><td>equivalent</td><td>Remarks</td></tr><tr><td><input type=text name=name1></td>
<td><input type=text name=name2></td><td><input type=text name=name3></td><td><input type=text name=name4></td><td><input type=text name=name5></td><tr><td>";

$sub1=$_POST['name2'];
$sub2=$_POST['name3'];
$sub3=$_POST['name4'];

$ave=($sub1+$sub2+$sub3)/3;
echo"$ave<br>";
if($ave==75){
echo "passing";
}elseif($ave>76){
echo "passed";
}else
echo "failed";
?><br>
<input type=submit value=compute></body></html>

================================================
thank you for those who said "no", because I did myself, better
================================================

commented: What the hell? No explaination of what your code does... +0

I would use javascript to calculate the values, all you need is and id in the <td> where you want the avg to be then an onkeypress="javascript: updateAvg();" on each of your names. In the function:

function updateAvg(){
var avg;
avg = (document.getElementById('name1').value + document.getElementById('name2').value + document.getElementById('name3').value)/3;
document.getElementById('[id of the <td>]').innerHTML = avg;
}

Something simple like that should do it. Of course you'll need id tags instead of name tags.

I'm newbie in learning javascript well this is the first time that I'll do this by the way thanksto your suggestion my question now is if Iwould input 20 persons should I repeat the computation code inside the javascript with different ID's??

You could do it that way, or make the function dynamic like this:

function updateAvg(td,pre,mid,final){
var avg;
avg = (pre + mid + final)/3;
document.getElementById(td).innerHTML = avg;
}

and call the function with this:

onkeypress="javascript: updateAvg('[id of the td]',document.getElementById('name2').value,document.getElementById('name3').value,document.getElementById('name4').value);"

Then on the next person the fields need new ids so something like:

onkeypress="javascript: updateAvg('[id of the td]',document.getElementById('name6').value,document.getElementById('name7').value,document.getElementById('name8').value);"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.