/    Sign up×
Community /Pin to ProfileBookmark

Duplicate a Script & Make Both Work?

Currently this script totals a column at the bottom. I’m trying to duplicate this script again in the <head> section changing the variable names to count another column seperately but it only counts 1 column(the first script). What do I need to change to be able to count both columns with both scripts. They are in the same <div name=”calcTable”> tags, not sure if thats the problem? Here is my code:

[code]
<head>
<script type=”text/javascript”>
function getElementsWithTagNameAndName(e2,t2,n2){
var findings2=new Array();var els2=e2.getElementsByTagName(t2);
for(var i2=0,l2=els2.length;i2<l2;i2++)if(els2[i2].getAttribute(“name”)==n2)findings2[findings2.length]=els2[i2];
return findings2;
}
function resolveTable(){
var els=getElementsWithTagNameAndName(document,”div”,”calcTable”)
var spanels=getElementsWithTagNameAndName(document,”span”,”avg”)
var infoels=new Array();
var theGrandTotal=0;
for(var i=0;i<els.length;i++)infoels[infoels.length]=getElementsWithTagNameAndName(els[i],”td”,”calcTd”);

var finalValue,j,tmpNumber;
for(i=0;i<spanels.length;i++){
finalValue=0;
for(j=0;j<infoels[i].length;j++){
if(!infoels[i][j])continue
tmpNumber=infoels[i][j].innerHTML
if(!tmpNumber)continue

tmpNumber=Number(tmpNumber.replace(/[^0-9eE.]/g,””))
if(isNaN(tmpNumber))continue
finalValue+=tmpNumber
}
theGrandTotal+=finalValue
spanels[i].innerHTML=”<b>”+finalValue.toFixed(0)+”</b>”
}
var ge=document.getElementById(“grandTotal”);
if(ge)ge.innerHTML=”<b>”+theGrandTotal.toFixed(0)+”</b>”

}
</script>
</head>

<body>

<!————————>
<div name=”calcTable”>
<!————————>
<table width=”675″ border=”0″ cellspacing=”1″ cellpadding=”2″ id=”table1″>
<tr valign=”top”>
<td width=”75″ align=”center” class=”o”><b>Enrolled #</td>
</tr>

<tr valign=”middle”>
<td align=”center” class=”offf”>24</td>
</tr>

<tr valign=”middle”>
<td align=”center” class=”offf”>36</td>
</tr>

<tr valign=”middle”>
<td align=”center” class=”offf” name=”calcTd”>57</td>
</tr>

<tr valign=”top”>
<td class=offff bgcolor=”#dddddd” align=”right”>Total Enrolled: <span name=”avg”></span><</td>
</tr>
</table>

<!————————>
</div>
<!————————>[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @HDC 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...