469,631 Members | 1,313 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

dynamic text using settimeout

Hi,

I am trying to create a header on a page that switches between 7 textitems
in an array.
using this code:

<script language="JavaScript">
season=new Array("summer","winter","fall","spring",")
i=0
function raise()
{
setTimeout('i=i+1',2000);
if(i>4){i=0}
}
</script>

</head>

<body onLoad="raise()">
<script language="JavaScript">

document.write(season[i]);
</script>

can anybody please explain me why this doesnot work.

greets,

Sybolt

Jul 23 '05 #1
2 1324

"S.Hoitinga" <s.********@chello.nl> wrote in message
news:oC*****************@amsnews03.chello.com...
Hi,

I am trying to create a header on a page that switches between 7 textitems
in an array.
using this code:

<script language="JavaScript">
season=new Array("summer","winter","fall","spring",")
i=0
function raise()
{
setTimeout('i=i+1',2000);
look at setInterval, setTimeout only runs once. It still won't work the way
I think you want it to because the document.write only executes when the
page is rendered.

Also, the variables in the setTimeout shouldn't be quoted

Start over... Post it up.

Look at: innerHTML and % (modulo arithmetic)

Jeff

if(i>4){i=0}
}
</script>

</head>

<body onLoad="raise()">
<script language="JavaScript">

document.write(season[i]);
</script>

can anybody please explain me why this doesnot work.

greets,

Sybolt

Jul 23 '05 #2
You asked that same question 6 days ago, with a lot of reply. It should
help you enough to get it working.

S.Hoitinga wrote:
Hi,

I am trying to create a header on a page that switches between 7 textitems
in an array.
using this code:

<script language="JavaScript">
season=new Array("summer","winter","fall","spring",")
i=0
function raise()
{
setTimeout('i=i+1',2000);
if(i>4){i=0}
}
</script>

</head>

<body onLoad="raise()">
<script language="JavaScript">

document.write(season[i]);
</script>

can anybody please explain me why this doesnot work.

greets,

Sybolt


Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Cybex | last post: by
2 posts views Thread by Randell D. | last post: by
8 posts views Thread by S.Hoitinga | last post: by
6 posts views Thread by Vanitha | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.