chewdonkey
chewdonkey

Reputation: 75

JavaScript outputs junk text

I am following a tutorial to learn JavaScript. The simple image scrolling script works but mine also outputs a lode of junk text, the example does not. Can anyone tell me what is wrong with my JavaScript syntax?

The junk text looks like this:

{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 Calibri;}} {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sl240\slmult1\lang9\f0\fs22 \par \par \tab \par \par \par \par \tab \par \par \par }

test.html

<!DOCTYPE html>
<head>
    <script src="imgscroll.js"></script>
</head>

<body>
    <img src="1.jpg" id="scroll" />
</body>
</html>

imgscroll.js

window.onload = rotate;

var images = new Array("1.jpg","2.jpg","3.jpg");
var thisImg = 0;

function rotate() {
    thisImg++;
    if (thisImg == images.length) {
        thisImg = 0;
    }
    document.getElementById("scroll").src = images[thisImg];
    setTimeout("rotate()", 3 * 1000);
}

Upvotes: 1

Views: 165

Answers (2)

imulsion
imulsion

Reputation: 9040

Your file is saved in RTF (Rich text format). Write it in notepad with no formatting, and it should work. Also, you might want to add an opening html tag (<html>) after <!DOCTYPE html>

Upvotes: 2

napolux
napolux

Reputation: 16074

Looks like one of your images is a word document with changed extension... Do a check on your files.

Upvotes: 1

Related Questions