error in code

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

    error in code

    I have a script to display a moving text in the status bar. I also
    want to display the change of ShowHead and ShowTail variables in the
    page. I wrote a
    function w()to do this. But it caused an error after it ran. Could
    you tell me what is wrong? Thanks a lot.
    Here is the code:
    <html>
    <head>
    </head>
    <body><script >
    var ShowString = " " //The
    first line must be blank
    + "JavaScript Scrolling Text Demo is here... "
    var ShowWidth = 1000
    var ShowHead = 0
    var ShowTail = ShowWidth
    var ShowLength = ShowString.leng th

    function Marquee(){
    var DisplayString
    if (ShowHead < ShowTail)
    DisplayString = ShowString.subs tring(ShowHead, ShowTail)
    else
    DisplayString = ShowString.subs tring(ShowHead, ShowLength)
    + ShowString.subs tring(0, ShowTail)
    ShowHead = (ShowHead + 1 ) % ShowLength
    ShowTail = (ShowTail + 1 ) % ShowLength
    window.status = DisplayString
    TimerID = setTimeout("Mar quee()",200)
    }
    Marquee();//above is OK.
    function w(){
    document.write( ShowHead +" "+ ShowTail);
    setTimeout("w() ",200);
    }
    w();
    </script>
    </body>
    </html>
  • Thomas 'PointedEars' Lahn

    #2
    Re: error in code

    chirs wrote:
    [color=blue]
    > I have a script to display a moving text in the status bar.[/color]

    Remove it, for the sake of your visitors and for your own sake.
    The status bar is a useful tool and you should not touch it,
    unless you know what you are doing (which is obviously not the
    case.)
    [color=blue]
    > I also want to display the change of ShowHead and ShowTail variables
    > in the page. I wrote a function w()to do this.[/color]

    Once a document has been loaded, document.write( ...) overwrites the
    document which causes all variables and functions to be undefined.
    Use DOM scripting instead of document.write( ...) if you need a timed
    presentation.
    [color=blue]
    > But it caused an error after it ran.[/color]

    `An error occured' is an insufficient error *description*.
    [color=blue]
    > [...]
    > <html>[/color]

    Before this tag the DOCTYPE declaration is missing.
    [color=blue]
    > <head>
    > </head>[/color]

    The charset declaration via the `meta' element,
    and the `title' element are missing here.
    [color=blue]
    > <body><script >[/color]

    The `type' attribute for the `script' element is missing.
    It should be at least <script type="text/javascript">.

    Your markup is invalid. See http://validator.w3.org/ for details.
    [color=blue]
    > [...]
    > function w(){
    > document.write( ShowHead +" "+ ShowTail);
    > setTimeout("w() ",200);
    > }
    > w();
    > [...][/color]


    PointedEars

    Comment

    Working...