PDA

View Full Version : Javascript: Images not showing up online. Show up on hard drive?????????????



jb33314
02 Mar 2008, 04:18 PM
I am making a navigation bar using Javascript. Nothing fancy. No drop down menus or any thing like that. All it does is read a cookie (cookie reading works so thats not the problem) and loads a certain image based on the data of the cookie.
This works fine when the webpage is stored locally on my computer. I even tried it locally on other computers. The problem is when I upload the page to a host the images dont show up. I tried taking one of the images out of the Javascript if statements and into the html directly. Then the image worked. So it cant be my src path to the image is wrong. Heres some code to show you how my page works.



<html><head>
<script type="text/javascript">
var theme;
(pseudocode)
if(cookie exists){theme=cookievalue;}
else{theme="theme1; cookievalue=theme;}//if cookie doesnt exisit creat a cookie with the default value
(/end pseudocode)
</script>
</head><body>
//some html here
<script type="text/javascript">
if(theme == "theme1")
{
document.write( "<img src=\"theme1im1.gif\" onMouseover=\"this.src='theme1im2.gif'\">");
}
else//theme="theme2"
{
document.write( "<img src=\"theme2im1.gif\" onMouseover=\"this.src='theme2im2.gif'\">");
}
</script>
</body>
</html>

MHoppal
06 Mar 2008, 10:37 PM
I am making a navigation bar using Javascript. Nothing fancy. No drop down menus or any thing like that. All it does is read a cookie (cookie reading works so thats not the problem) and loads a certain image based on the data of the cookie.
This works fine when the webpage is stored locally on my computer. I even tried it locally on other computers. The problem is when I upload the page to a host the images dont show up. I tried taking one of the images out of the Javascript if statements and into the html directly. Then the image worked. So it cant be my src path to the image is wrong. Heres some code to show you how my page works.



<html><head>
<script type="text/javascript">
var theme;
(pseudocode)
if(cookie exists){theme=cookievalue;}
else{theme="theme1; cookievalue=theme;}//if cookie doesnt exisit creat a cookie with the default value
(/end pseudocode)
</script>
</head><body>
//some html here
<script type="text/javascript">
if(theme == "theme1")
{
document.write( "<img src=\"theme1im1.gif\" onMouseover=\"this.src='theme1im2.gif'\">");
}
else//theme="theme2"
{
document.write( "<img src=\"theme2im1.gif\" onMouseover=\"this.src='theme2im2.gif'\">");
}
</script>
</body>
</html>


I made the one glaring problems in red.

1: Your variable definition isn't completely quoted.
2: I'm not sure if that needs to be quoted, or if you just mistyped the definition in the previous code.

That's all I caught. See if it magically fixes the problem (It could -- PHP gives some nasty MySQL errors even if you miss one semicolon 20 lines previous to the query in the script).

Regards.