Jump to content

looping


jnf555

Recommended Posts

hi any one help with this script i want it to go from one name to another one without stopping <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><title>new project</title><head></head><body><script type="text/javascript">var names = ['john','gail','julie','jason','zoe'];var allnames = names.length;var i = 0;function loop(){if (i > (allnames - 1))i = 0;{document.write(names);}i++;loopTimer = setTimeout('loop()',3000);}loop();</script></body></html> thanks for any help

Link to comment
Share on other sites

What you really want is for the document to have an element, like a div or something, and update its innerHTML property every time the loop iterates. The div should have an id so you can get a reference to it using document.getElementById().

Link to comment
Share on other sites

there we go this works fine <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><title>new project</title><head></head><body><div id="jnf"></div><script type="text/javascript">var jnf2 = document.getElementById('jnf'); var names = ['john','gail','julie','jason','zoe'];var allnames = names.length;var i = 0;function loop(){if (i > (allnames - 1))i = 0;{jnf2.innerHTML = (names);}i++;loopTimer = setTimeout('loop()',3000);}loop();</script></body></html>

Link to comment
Share on other sites

<p>Here is the code</p><p> </p><div><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></div><div><html></div><div><title>new project</title></div><div><head></div><div></head></div><div><body onload="loop()"></div><div> </div><div> </div><div><script type="text/javascript"></div><div>function loop(){</div><div>var names = ['john','gail','julie','jason','zoe'];</div><div>var allnames = names.length;</div><div> </div><div>for (var i = 0; i < names.length; i++) {</div><div> </div><div> </div><div> document.write(names+"<br>");</div><div> </div><div>}</div><div> </div><div>}</div><div></script></div><div></body></div><div> </div><div> </div><div> </div><div> </div><div></html></div><div> </div>

Link to comment
Share on other sites

<p>Here is the code</p><p> </p><div><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></div><div><html></div><div><title>new project</title></div><div><head></div><div></head></div><div><body onload="loop()"></div><div> </div><div> </div><div><script type="text/javascript"></div><div>function loop(){</div><div>var names = ['john','gail','julie','jason','zoe'];</div><div>var allnames = names.length;</div><div> </div><div>for (var i = 0; i < names.length; i++) {</div><div> </div><div> </div><div> document.write(names+"<br>");</div><div> </div><div>}</div><div> </div><div>}</div><div></script></div><div></body></div><div> </div><div> </div><div> </div><div> </div><div></html></div><div> </div>
Why there is so many divs? its like total mess. Try adding code to codearea it might help bit. Cleared the code bit
<p>Here is the code</p><p> </p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><title>new project</title><head></head><body onload="loop()"><script type="text/javascript">function loop(){var names = ['john','gail','julie','jason','zoe'];var allnames = names.length;for (var i = 0; i < names.length; i++) {document.write(names[i]+"<br>");}}</script></body></html>

Edited by Mudsaf
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...