SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Member
    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>
    Thanks.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by itsrick View Post
    The variables are all global and defined correctly in the functions. I hope this makes sense.
    Global variables are defined outside functions. Though to be sure, show us the JavaScript code.

  3. #3
    SitePoint Member
    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.

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    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)?

  5. #5
    SitePoint Member
    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

  6. #6
    SitePoint Member
    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?

  7. #7
    SitePoint Wizard Pepejeria's Avatar
    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.

  8. #8
    SitePoint Member
    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.

  9. #9
    SitePoint Member
    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]
    should be
    Code:
    myList2['loopJPG']
    But as pepejeria said, we'll need to see some code to fully understand the problem.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •