The error is telling you that there is no element called BarName. Fire up your debugger and step through the code. Your little snippet doesn't tell me much other than how you are setting the value BarName.
Everything in Javascript is essentially an object. So arrays, integers, and functions are all objects. To pass an array, you handle it just like you would anything else.
Hello again,
Well, I realized that my code was slightly wrong in that each BarName is "bar" + LoopCount + 1 so I changed it to correct that error, and it still does not work.
I have no debugger to step through the code with. Could you recommend one?
Here is the entie script, maybe you could tell me why BarName is null after looking at it. I've previously attempted to feed variables in as an id for the document commands without success, and have had to use quoted strings where I wanted to use a variable, so I'm sure somehow that is the problem.
<script type="text/javascript">
function setCounts(AgentName, Range, DaysCounts) {
for (LoopCount in DaysCounts) {
BarNumber = LoopCount + 1
BarName = "bar" + BarNumber;
document.getElementById(BarName).style.height= ((300.0 / Range) * DaysCounts[LoopCount]);
document.getElementById(BarName).title= DaysCounts[LoopCount] + " " + AgentName + "s";
}
document.getElementById('titlebar').innerHTML= "<center>February " + AgentName + " Counts</center>";
document.getElementById('increment2').innerHTML= (Range / 6.0)
document.getElementById('increment3').innerHTML= ((Range / 6.0) * 2);
document.getElementById('increment4').innerHTML= ((Range / 6.0) * 3);
document.getElementById('increment5').innerHTML= ((Range / 6.0) * 4);
document.getElementById('increment6').innerHTML= ((Range / 6.0) * 5);
document.getElementById('increment7').innerHTML= ((Range / 6.0) * 6);
}
function setMozillaCounts() {
AgentName = "Mozilla Browser";
Range = 1200;
var MozillaCounts = [923, 650, 777, 1234, 555, 888, 1000, 550, 609, 806, 444, 555, 876, 456, 678, 987, 1150, 560, 179, 678, 984, 542, 567, 420, 1000, 444, 777];
setCounts(AgentName, Range, MozillaCounts);
}
</script>
Here is proof that "bar1", and "bar2" exist as ids at least. They go up to 28 of course for February.
<div class="bar" id="bar1" title="1200 Visitors" style="position: absolute; height: 33.333333333%;"></div>
<div class="bar" id="bar2" title="960 Visitors" style="position: absolute; left: 3.571428571%; height: 80px;"></div>
Thanks again, Ray Parrish
Edited by Ray Parrish, 13 March 2010 - 09:05 AM.