SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Simple Newbie Question
Hybrid View
-
Jan 22, 2004, 16:43 #1
- Join Date
- Jun 2003
- Location
- _root.europe.uk.london
- Posts
- 965
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Simple Newbie Question
Hi there,
I'm trying to display a random image that is selected from an array. What's causing the problem is the route to the image that I'm trying to print to the page. I'm sure I'm doing something wrong with escaping characters ... or something!!
Anyway, here's the code
Code:<script language="javascript"> document.write("<img src='images\/" + castlepic[lucky] + "\.gif'" + "width='75' height='70' alt=''></td>"; </script>
What I'm trying to get is a line that will print out like this:
Code:<img src=images/dog.gif width='75' height='70' alt=''></td>
-
Jan 22, 2004, 16:49 #2
You don't have to escape slashes or periods in quotes. Your document.write should look more like this:
Code:<script language="javascript"> document.write("<img src="images/" + castlepic[lucky] + ".gif" + "width='75' height='70' alt=''></td>"; </script>
Code:<script type="text/javascript"> function setImage(sourceFile) { document.getElementById("randomImage").setAttribute("src", sourceFile); } </script>
HTML Code:<img id="randomImage" src="/default.gif" alt="Random Image" />
Code:setImage(castlepic[lucky]);
Hope this helps!
Bookmarks