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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

view images 2

Status
Not open for further replies.

celticking

Technical User
Feb 15, 2001
69
US
I have used some javascript to show a main picture on my page. Below is 3 thumbnails that when clicked should replace the main picture but doesn't work. When i open the page, everything is in place, when i select the thumbnail, the main picture area goes blank with the little not found cross in the top left corner. Here is the code i have used.
<head>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
ns3up = (browserName == &quot;Netscape&quot; &amp;&amp; browserVer >= 3);
ie4up = (browserName.indexOf(&quot;Microsoft&quot;) >= 0 &amp;&amp; browserVer >= 4);
function doPic(imgName) {
if (ns3up || ie4up) {
imgOn = (&quot;&quot; + imgName);
document.mainpic.src = imgOn;
}
}
</script>
<body>
<table width=165 height=220 border=0 cellspacing=0 cellpadding=0>
<tr>
<td colspan=4 align=center height=&quot;180&quot;>
<img name=&quot;mainpic&quot; src=&quot;art/pic1.jpg&quot; width=168 height=180 border=0></td>
</tr>
<tr>
<td width=&quot;54&quot; height=&quot;65&quot; valign=&quot;top&quot;>
<a href=&quot;javascript:doPic('pic2.jpg');&quot;>
<img src=&quot;art/pic2.jpg&quot; width=54 height=63 border=1></a></td>
<td width=&quot;54&quot; valign=&quot;top&quot;>
<a href=&quot;javascript:doPic('pic3.jpg');&quot;>
<img src=&quot;art/pic3.jpg&quot; width=54 height=63 border=1></a></td>
<td width=&quot;54&quot; valign=&quot;top&quot;>
<a href=&quot;javascript:doPic('pic4.jpg');&quot;><img src=&quot;art/pic4.jpg&quot; width=54 height=63 border=1>
</a></td>

I hope someone can help with this. I've been pulling my hair out all day as it look correct to me.
Many thanks.
 
Well, I got it to work - I think you have probably got your images in the wrong place - make sure of path and filename.;)

Also these images are being loaded every time == slow. You want to preload them using the Image() constructor - this way you can have them different size from your thumbnails, without stretching them.
image preload
<script>
...
var img_one = new Image();
img_one.src = &quot;art/pic1.jpg&quot;;
...
/* Access via img_one.src - only loaded once, when page
loaded */
</script>


I also don't understand this:

function doPic(imgName) {
if (ns3up || ie4up) {
imgOn = (&quot;&quot; + imgName);
document.mainpic.src = imgOn;
}
}

You are actually passing the full path to the function, you don't need to store it - this will work too.

function doPic(imgName) {
if (ns3up || ie4up) {
document.mainpic.src = imgName;
}
}


You should also experiment with sending objects (by name or id) in function calls - saves a bit of mucking around.:)



b2 - benbiddington@surf4nix.com
 
Sorry, i have to apologize, it's working now. There was a problem with the path. Thanks for your help, i really appreciate it.
 
Hi celticking!
I have an advise for you.
In your script you make sure that preloading and image change works. But how do you do it?! You determine whether the NN or IE version is appropriate.
And what other browsers? Like Opera, for example, that does it lot less good, but you don't give it a chance!

He's what you can place instead of (ns3up || ie4up):
if (document.images)
that's all, and you don't even need all that part of browserVer, ns3up, ie4up - it's just rubbish.

Abdrew | starway@mail.com
 
Opera - isn't that somewhere rich people go for a nap?;)
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top