Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with image in javascript

Status
Not open for further replies.

rry2k

Programmer
Jun 28, 2001
678
US
<html>
<head>
<script language=&quot;javascript&quot;>
if (screen.width > 800)
{
document.write(&quot;<img src='images/untitled2.gif'><FONT COLOR='#006699'>&quot;)
}
if (screen.width < 800)
{
document.write(&quot;<img src='images/untitled2test.gif'><FONT COLOR='#006699'>&quot;)
}
</script>
</head>
</html>
 
Good observation. Actually though, <> 800 was just an example.
 
hey guy, where is your problem ??? you wrote the code but no question. Water is not bad as long as it stays out human body ;-)
 
Didn't you forget the body tag ? Water is not bad as long as it stays out human body ;-)
 
I was having a problem with the image line within the javascript but I got help and it is resolved.

Thanks..R
 
hey im a newb at html basically but i take it that it shows a dif image at a dif screen resolution and i tried it but it didn't work, if this is what it does can you tell me how to get it to work, and if im wrong then just forget i posted anything
 
Well, it's missing the body tags, and if you're viewing at 800 x 600 resolution you won't see any image because one statement says if it's greater than 800, and the other if it's less than 800.

Also, the code above is missing the semi-colon at the end of each of the document.write statements.

Try this: (of course you'll need a couple of images ... blue.gif and red.gif)

-----------------------------
<html>
<head>
<script language=&quot;javascript&quot;>
if (screen.width > 800){
document.write(&quot;<img src='blue.gif'><br><b>Greater than 800</b>&quot;);
}
if (screen.width<= 800){
document.write(&quot;<img src='red.gif'><br><b>Less than or equal to 800</b>&quot;);
}
</script>
</head>
<body>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top