...

View Full Version : how to calculate values in tables?



tHaZ
03-05-2005, 03:05 AM
Say i have a table with the following numbers:

20 | 30 | 50

What i want is to automatically calculate cell 1 and cell 2, and give the result in cell 3.
20+30=50.

So when i update the numbers in cell 1 and 2, it will automatically update in cell 3.
Does anybody know of a javascript that can do something like this?
Or is it easy to make?

thanks...

codegoboom
03-05-2005, 05:14 AM
In your function which updates the cells, add the numbers... :)

tHaZ
03-05-2005, 02:10 PM
thanks for the answer.
but how do i make a function that updates the cells then?

codegoboom
03-06-2005, 01:51 AM
What cells? I see no cells... :D

vwphillips
03-06-2005, 12:00 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
var AddAry=new Array;
var add,result;

function Add(obj){
if (isNaN(obj.value)&&obj.value.charAt(0)!='.'&&obj.value.charAt(0)!='+'&&obj.value.charAt(0)!='-'){
alert('Numbers Please');
obj.value=obj.value.substring(0,obj.value.length-1);
return;
}
add=1;
for (i=0;i<AddAry.length;i++){
if (AddAry[i]==obj){
add=0;
}
}
if (add){
AddAry[AddAry.length]=obj;
}
result=0;
for (i1=0;i1<AddAry.length;i1++){
result=result+AddAry[i1].value*1;
}
if (!isNaN(obj.value)){
document.getElementById('Result').value=result;
}
}
//-->
</script></head>

<body>
<input name="" size="10" onkeyup="javascript:Add(this);">
<input name="" size="10" onkeyup="javascript:Add(this);">
<input id="Result" size="10" disabled="disabled">

</body>

</html>

tHaZ
03-06-2005, 09:56 PM
thank you vwphillips :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum