SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: variables in div tags?
-
Mar 30, 2007, 00:14 #1
- Join Date
- Mar 2007
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
variables in div tags?
I am having trouble displaying a picture in a div tag in the body of my page. I think the problem lies in the fact that I need to use a variable to display the image and it is not carrying over for some reason.
The variables are all global and defined correctly in the functions. I hope this makes sense. If anyone can offer some advice, I will gladly try any thing. I can't even come up with any more search strings.
Here is the latest code I tried for inside the div tags...
Code:<div id="jpgcontent"> <script language="Javascript"> document.write("<img name='jpg' src='jpg files/" + myList2[loopJPG] + "' width='811' height='607'>"); </script> </div>
-
Mar 30, 2007, 00:34 #2
-
Mar 30, 2007, 13:39 #3
- Join Date
- Mar 2007
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
wow thanks for the quick reply. Sorry for the delay in posting - this is the first time I've been in front of a computer all day (that's both good and bad).
I don't have the code with me right now but I know that all of my variables are global because I am using them all in a few different functions where they keep the same value.
My current problem lies within this div tag though. I need to display a picture in a div (so i can show/hide it). I have written the code for this and it works. However, when I try use a variable (from the javascript functions in the html head) it will not display the picture.
This is a huge dillemma because I cannot display the picture without the variable.
I have tried so many different variations already it is hard to list them all. When I get back to my own computer I will put the code up but for now I would really appreciate it if anyone could offer some friendly advice. Thanks.
-
Mar 30, 2007, 14:08 #4
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What errors do you get in the JavaScript console (Firefox)?
-
Mar 30, 2007, 14:11 #5
- Join Date
- Mar 2007
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
no errors just a blank page when it is supposed to load the image.
No javascript variables in the body = div appears w/ image
With javascript variables in the body = blank page
-
Mar 30, 2007, 14:21 #6
- Join Date
- Mar 2007
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I just tried a simple test. In the div I posted above, I wrote
document.write("hello"); which worked.
But when I put
document.write(myList2[0]); nothing happened.
myList2[0] is global because it is passed from one function to the other and I know it holds its value through the script.
What is going on here? Can you not carry javascript variables from the head to the body?
-
Mar 30, 2007, 14:25 #7
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes you can. I think I need to see some code to figure out whats wrong.
-
Mar 30, 2007, 14:34 #8
- Join Date
- Mar 2007
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you for trying to help. There is a hole in the wall shaped exactly like my head - it is no coincidence. I will post some code when I get back to the house in about an hour.
-
Mar 31, 2007, 07:32 #9
- Join Date
- Nov 2006
- Posts
- 16
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Also, in your original code you tried to iterate through an array with a string without quotes:
myList2[loopJPG]
Code:myList2['loopJPG']
Bookmarks