/    Sign up×
Community /Pin to ProfileBookmark

Help Adding Column Values

I’m trying to get this to work and don’t know what is wrong with the code. This is a very simple script to add the total of 2 columns, here is the code:

Thanks in advanced,
Aaron

<html>
<head>

<script language=”javascript”>
var cellcounter = 0;
var colValues = new Array(2);
var colTotals = 0;
var avgCorrector = 0;
var colAvg = 0;

function averageValues() {
for (i=0;i<=cellcounter-1;i=i+1)
{
if (isNaN(colValues[i])==true II colValues[i] == “”) {
colValues[i] = 0;
avgCorrector = avgCorrector + 1;
}
else
{
colTotals = colTotals + parseFloat(colValues[i]);
}
}
colAvg = colTotals / (cellcounter – avgCorrector);
colAvg = Math.round(colAvg * 10)/10;
document.getElementById(“avg1”).innerHTML = colTotals;
}

</script>

</head>
<body onload=”averageValues();”>

<table width=”665″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td>Office #</td>
<td>
<script language=”javascript”>
document.write(“2”);
colValues[cellcounter]=”2″;
parseFloat(colValues[cellcounter]);
</script>
</td>
</tr>

<tr>
<td>Office ID</td>
<td>
<script language=”javascript”>
document.write(“7”);
colValues[cellcounter]=”7″;
parseFloat(colValues[cellcounter]);
</script>
</td>
</tr>

<tr>
<td>Total Amount: </td>
<td><span id=”avg1″> …Total should go here </span></td>
</tr>
</table>

</body>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@adalbyauthorDec 01.2005 — Can anyone help me on this one. Has anyone seen a better script that does this??

Thanks In Advanced,

Aaron
×

Success!

Help @adalby spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...