dynamic text using settimeout

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • S.Hoitinga

    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="JavaS cript">
    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="JavaS cript">

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

    can anybody please explain me why this doesnot work.

    greets,

    Sybolt



  • Jeff Thies

    #2
    Re: dynamic text using settimeout


    "S.Hoitinga " <s.hoitinga@che llo.nl> wrote in message
    news:oCkAc.6577 $Zs4.3110@amsne ws03.chello.com ...[color=blue]
    > Hi,
    >
    > I am trying to create a header on a page that switches between 7 textitems
    > in an array.
    > using this code:
    >
    > <script language="JavaS cript">
    > season=new Array("summer", "winter","fall" ,"spring",")
    > i=0
    > function raise()
    > {
    > setTimeout('i=i +1',2000);[/color]

    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

    [color=blue]
    > if(i>4){i=0}
    > }
    > </script>
    >
    > </head>
    >
    > <body onLoad="raise() ">
    > <script language="JavaS cript">
    >
    > document.write( season[i]);
    > </script>
    >
    > can anybody please explain me why this doesnot work.
    >
    > greets,
    >
    > Sybolt
    >
    >
    >[/color]


    Comment

    • Vincent van Beveren

      #3
      Re: dynamic text using settimeout

      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:
      [color=blue]
      > Hi,
      >
      > I am trying to create a header on a page that switches between 7 textitems
      > in an array.
      > using this code:
      >
      > <script language="JavaS cript">
      > 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="JavaS cript">
      >
      > document.write( season[i]);
      > </script>
      >
      > can anybody please explain me why this doesnot work.
      >
      > greets,
      >
      > Sybolt
      >
      >
      >[/color]

      Comment

      Working...