Well, it's part of a larger script, so I'll put the relevant parts.
- function updatePart (hd, sz, dispType) {
-
var totalHDspace = document.getElementById(hd + '-total');
-
//var totalHDspaceUp = document.getElementById(hd + '-total');
-
-
switch (dispType) {
-
case "update":
-
totalHDspaceUp.innerHTML = parseInt(totalHDspaceUp.innerHTML) + sz;
-
break;
-
-
case "create":
-
totalHDspace.innerHTML = parseInt(totalHDspace.innerHTML) + sz;
-
break;
-
}
-
-
}
-
-
updatePart('hdpart-1', 123, 'create');
[PHP]<dl id="part_list">
<dt>Hard Drive Space</dt>
<?php
for ($i=0; $i<count($ksServerCfg['hard_drive']); $i++) {
echo "<dd>HD#".($i+1).": <span id='hdpart-".($i+1)."-total'>0</span> GB of ".$ksServerCfg['hard_drive'][$i]." GB used</dd>";
}
?>
</dl>[/PHP]
I use PHP to loop through all of the parts I need (in this case there are three), and assign them a unique ID (hdpart-1-total, hdpart-2-total, etc). Then I call updatePart() as the user interacts with the site. It works fine as far as updating the span tag, it just doesn't update it correctly.
I thought that this may be because I was originally calling totalHDspace multiple times and didn't give it a unique name, so I have two of them up there. I've used alert() to watch the different variables as they go through the function, and it all works fine until it tries to pull the innerHTML and add it to sz.
Oh, when I do this...
- updatePart('hdpart-1', 123, 'create');
-
alert(parseInt(totalHDspace.innerHTML) + sz);
I get '0123'