A couple of problems with this code:
The values for count (0) and delay (5000) are passed with 'onload' in the body tag.
First problem, array index 1 is the first thing to display. Is 'i' incremented at the start of the for loop?
Next (biggest) problem, 'count' is undefined when the function calls itself via the setTimeout bit (so is delay).
What should happen is that everything in the 'newsitem' array gets listed starting with element 0, then looping through the array and displaying things line by line. Output goes to a text input box.
I'm a javascript n00b; the only things I've seen passed to functions via setTimeout are strings (or nothing) on any example I've been able to find.
Code:
function newsbar(count, delay)
{
var newsitem = new Array();
newsitem[0] = "some news";
newsitem[1] = "more news";
for (i=0;i<newsitem.length;i++)
{
if(count==i)
{
document.newsform.newsinput.value=newsitem[i];
count++;
if(count>=newsitem.length)
{
count = 0;
}
news=setTimeout("newsbar(count, delay)", delay);
}
}
}
The values for count (0) and delay (5000) are passed with 'onload' in the body tag.
First problem, array index 1 is the first thing to display. Is 'i' incremented at the start of the for loop?
Next (biggest) problem, 'count' is undefined when the function calls itself via the setTimeout bit (so is delay).
What should happen is that everything in the 'newsitem' array gets listed starting with element 0, then looping through the array and displaying things line by line. Output goes to a text input box.
I'm a javascript n00b; the only things I've seen passed to functions via setTimeout are strings (or nothing) on any example I've been able to find.