JavaScript Example 1-7
Scrolling Text Window

Click Here for Previous JavaScript Tutorial Home Click Here for Next

Example code from Dr. Clue's Javascript tutorial, http://www.drclue.net/F1.cgi/HTML/JAVA/JAVA.html

Example of a scrolling text window...

Source Code

The JavaScript function which performs the scrolling is called when the body is loaded:

  <body onload="scroll()">

The function scroll() is defined as follows:

<script type="text/javascript" language="JavaScript">
    <!-- Hide Code  Starts -----
   var id;
   var msg="*** Welcome to Dr. Clue's HTML/CGI Guide *** I hope you enjoy \
using this guide as much as I enjoyed creating it ;) "; 

   function scroll() 
    {
    var lchar;
     lchar  = msg.substring(0,1);
     msg   += lchar;
     msg    = msg.substring(1,msg.length);
         
         // write to form "JavaForm"
     document.JavaForm.display.value = msg.substring(0,55);
         
         // write to window status bar
     window.status = msg.substring(0,55);
         
         // call ourselves again after a certain interval
     id     = setTimeout("scroll()",100); 
    }    
    // Hide Code Ends --->
</script>

Note that it writes both to the window status bar and to a Form element called "JavaForm". The scrolling text box above is "JavaForm". The HTML code for it is:

    <form name="JavaForm">
      <input type="TEXT" name="display">
    </form>

You can actually type into it, but you won't see much.

 
Click Here for Previous JavaScript Tutorial Home Click Here for Next