Forum Moderators: open

Message Too Old, No Replies

JS for beginners / me

Very simple ".js" image problem

         

PanUK

3:53 pm on Oct 30, 2003 (gmt 0)

10+ Year Member



Hi All,

Started out a couple of hours ago wanting to place multiple images in .js files complete with links and alts. The files I then plan to rotate on load.

Problem, for some reason I can't even a single image to load from the .js file. All files and the gif are in the same folder. I can change the test.js for a simple script showing the date etc. and that pops up fine. I can paste the <img src="aliens.gif" width="70" height="59"> into the body bypassing the test.js file and it works fine. But place it in the test.js and it throws some sort of syntax error. Maybe it's just me only having 4 hours sleep in the last 30 or maybe it's just that i haven't used .js before. Please put me out of my misery before I take up monitor throwing.(ok a few pencils then.)

contents test.js file.....
<img src="aliens.gif" width="70" height="59">

contents test.html body.....
<script src="test.js" language="JavaScript"></script>

Sinner_G

4:03 pm on Oct 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure what you want to do, maybe you should look into server side includes instead of JS.

In any case, if you want that line written by the JavaScript, you should use the document.writeln command:

document.writeln("<img src='aliens.gif' width='70' height='59'>")

PanUK

4:19 pm on Oct 30, 2003 (gmt 0)

10+ Year Member



Hi thanks for answering, to be clearer I don't want to write anything.

I just want to load several small images on page load to use as a pictorial menu. Storing them as .js and rotating the .js seems to be the simplest solution.

I have simplified it down to a single image to try to work out why it will not work but I can't even get the single image to load from the .js .

I'm missing something, I have even uploaded it and changed the paths to full url in case it was a local problem.

Sinner_G

4:51 pm on Oct 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Including the line as in my previous msg into your test.js file instead of the <img src="aliens.gif" width="70" height="59"> will have the same effect as writing that line into the html file. Just mind that it is an L, not a capital I in the writeln part.

PanUK

5:09 pm on Oct 30, 2003 (gmt 0)

10+ Year Member



Many thanks Sinner_G, the mud has been diluted. :)