Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > simple image swap question

simple image swap question
Thread Tools
Forum Regular
Join Date: Oct 2002
Location: upstairs
Status: Offline
Reply With Quote
Mar 9, 2004, 11:31 AM
 
Hello-

I'm designing a site for a stone supplier and I'm having a little trouble figuring out a basic problem. I would like to swap out an image (actually 47 images) via a text link WITHOUT reloading the page. I just don't want to create more pages when I know this can be done with either CSS, DHTML, or PHP. I'm up to speed on HTML and CSS for fonts and leading. I'm not up to speed on dynamic content though. I don't want to preload any of the images for obvious speed reasons. Should I use a layer and target it? I've never used layers before and wasn't sure about their compatability. Any help in figuring it out would be greatly appreciated.

Here is the page in question here . You can see the menu on the left, I want to swap out the image on the right via those hyperlinks-

somebody school me please-
---------------------------------------
     
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Mar 9, 2004, 12:28 PM
 
In your html, where you call the image on the right
Code:
<img src="images/inventory_03.jpg" width="481" height="251" alt="">
add a name attribute like so:

Code:
<img src="images/inventory_03.jpg" width="481" height="251" alt="" name="myNameisAwesome">
Then, add a little javascript to your hyperlink:

Code:
<a href="#" onClick="window.document.myNameisAwesome.src='inventory_X.jpg'; return false;">
Where 'inventory_X.jpg' is the name of the image to be swapped in. Also, you can substitute any name you'd like for 'myNameisAwesome' too. The 'return false' bit prevents browsers from reloading the page.
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 9, 2004, 02:14 PM
 
window.document.myNameisAwesome.src
Bleh. Isn't that only an MSIE thing? I'd go for giving the element an ID and using
Code:
document.getElementById("whateverID").src
since it's much more standards based an nice

Anyhoo, in regards to the question, make a wee function like
Code:
function swapImage(what) { document.getElementById("imageName").src = what; }
and then have
Code:
<a href="whatever.html" onmouseover="swapImage('hello.jpg')"> hi</a>
as it reduces your markup a bit...

There's obviously loads of ways of refining this for your needs...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Mar 9, 2004, 03:01 PM
 
Originally posted by Black Book:
Bleh. Isn't that only an MSIE thing? I'd go for giving the element an ID and using
… since it's much more standards based an nice


Very true, your example is more inline with w3c's standard.

But I bet the other way will probably cause less grief for someone who isn't very familiar with javascript.
     
Senior User
Join Date: Jan 2001
Status: Offline
Reply With Quote
Mar 9, 2004, 03:15 PM
 
don't want to seem to pissy here, but isn't there a way of categorizing the stone categories so a user doesn't have to browse through 47 names to find what they want?

thumbnails perhaps or at least an outline?
(Last edited by cowerd; Mar 9, 2004 at 04:04 PM. )
yo frat boy. where's my tax cut.
     
Forum Regular
Join Date: Oct 2002
Location: upstairs
Status: Offline
Reply With Quote
Mar 10, 2004, 07:10 AM
 
Hello again-

Thanks to all who responded. Both worked great, I feel like an idiot since it was so simple! You guys are quick to respond!

As for the outline/layout question: Man I hear ya! This client has been difficult to work with every step of the way. I had broken down the stone by type and mocked up thumbnail pages but they are already have a brochure where the stone is listed by number! I became tired of persuading them to change their mind and figured I would show them the two side by side. Thanks for being pissy
---------------------------------------
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2