JavaScript question

Hurricane

Sleeping Dragon
Joined
Dec 6, 2001
Messages
1,197
Ok, I'm a total newbie, so bear with me. :)

I want to have a web page, which displays a number of pictures defined in a number of separate .js files. The idea is that the .js files can be changed with macros in excel, thus changing which picture to display on the web page.

The macro writes the javascript file, and depending on the result of the excel calculations, should write a script that either displays picture a, b or c.

The html file then just calls these js files in the appropriate location of the file.

I'll illustrate with an example.

I have 3 js files:
* file1.js is to display image a
* file2.js is to display image b
* file3.js is to display image c

The test.html file has a table:

Code:
<body>
<table>
<tr><td>current images:</td></tr>
<tr><td>
<script language="JavaScript">
document.write("<script src='file1.js'><\/script>")
</script>
</td></tr>
<tr><td>
<script language="JavaScript">
document.write("<script src='file2.js'><\/script>")
</script>
</td></tr>
<tr><td>
<script language="JavaScript">
document.write("<script src='file3.js'><\/script>")
</script>
</td></tr>
</table>
</body>

The problem is that I can't get the images to display. So if anybody could give me the correct JavaScript code, and correct the html code if it's incorrect, I would be more than grateful. :)

The Javascript files look something like this:

Code:
myimage = new Image(50, 10)
myimage.src = 'status1.gif'
 
Originally posted by Hurricane
Code:
myimage = new Image(50, 10)
myimage.src = 'status1.gif'
Instead of doing this it'd probably be simpler to use this code:

Code:
document.write("<img src=status1.jpg width=50 height=10>");

Although it's not as neat...

If you're using javascript, I think you're supposed to use 'var' to declare a variable and also end all lines with semi-colon ';'. Not sure how picky the script-engine is though?
 
Great! That seems to work. Simple and good. :goodjob:

I read some JavaScript FAQ, and the semicolon at the end is apparently optional. You allegedly only need it if you put several statements on the same line.
 
Back
Top Bottom