[SOLVED] multiple image rollover not restoring image

This is a discussion on "[SOLVED] multiple image rollover not restoring image" within the JavaScript Forum section. This forum, and the thread "[SOLVED] multiple image rollover not restoring image are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Nov 5th, 2007, 10:03
Reputable Member
Join Date: Mar 2006
Location: UK
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] multiple image rollover not restoring image

I have two pairs of images that are linked.

When user rollovers img1 it changes to img2, and on another part of the page (on an image map) img3 changes to img4. Likewise when the user rolls over img3, then img1 changes too.

My problem is the imgRestore command only seems to work on one pair of images at a time. i.e. img1 restores but img 3 doesn't and vice versa

Any tips on how to get both pairs of image to restore on mouseOut?

Code: Select all
  

<td>

<a href="#"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('img1','','../../_globalimages/enOnly/lin/img2.gif',1);MM_swapImage('img3','','../../_globalimages/enOnly/lin/img4.gif',1)">  
        
        <img src="../../_globalimages/enOnly/lin/sd.gif" alt="go to South Denbighshire district" name="southDenbighshire_text" width="120" height="15" border="0" id="southDenbighshire_text" /></a>

</td>
and the image map..
Code: Select all
<area shape="poly" coords="182,49,181,62,168,76,183,89,180,129,189,130,201,113,229,110,223,102,227,84,218,66,205,68,200,55" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('img1','','../../_globalimages/enOnly/lin/img2.gif',1);MM_swapImage('img3','','../../_globalimages/enOnly/lin/img4.gif',1)"  alt="go to South Denbighshire district" title="South Denbighshire district"  />

Last edited by Rakuli; Nov 5th, 2007 at 10:30. Reason: restored white space
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 5th, 2007, 10:15
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple image rollover not restoring image

Can you show the actual javascript functions please. I can't see what might be causing the error without seeing them
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 5th, 2007, 10:23
Reputable Member
Join Date: Mar 2006
Location: UK
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple image rollover not restoring image

Would any problem be here? I thought it would be in the html. Or do I misunderstand?

Code: Select all
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 5th, 2007, 10:46
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple image rollover not restoring image

Yeah, I needed to see what your code was doing so I could see how it was wrong in your HTML

I think your problem is that you are calling the function too often, you only need to call it once and add all the necessary images to it...



Code: Select all
<td>

<a href="#"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('img1','','../../_globalimages/enOnly/lin/img2.gif''img3','','../../_globalimages/enOnly/lin/img4.gif',1)">  
        
        <img src="../../_globalimages/enOnly/lin/sd.gif" alt="go to South Denbighshire district" name="southDenbighshire_text" width="120" height="15" border="0" id="southDenbighshire_text" /></a>

</td>


<area shape="poly" coords="182,49,181,62,168,76,183,89,180,129,189,130,201,113,229,110,223,102,227,84,218,66,205,68,200,55" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('img1','','../../_globalimages/enOnly/lin/img2.gif','img3','','../../_globalimages/enOnly/lin/img4.gif',1)"  alt="go to South Denbighshire district" title="South Denbighshire district"  />
The code's a bit hard to read but that may help
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 5th, 2007, 14:38
Reputable Member
Join Date: Mar 2006
Location: UK
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple image rollover not restoring image

You are right, brilliant, thanks.

Just needed an comma between the two image swaps too.

Cheers for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hover over text to rollover an image? Dapandyman Web Page Design 3 Feb 24th, 2008 08:12
Rollover image links - eek...why aren't they working?? supanova75 Web Page Design 7 Nov 15th, 2007 12:47
Rollover image with links on new image stoob JavaScript Forum 2 Feb 8th, 2007 22:05
image rollover renren Web Page Design 3 Feb 13th, 2006 12:54
Rollover Image Problem! edejo JavaScript Forum 2 Dec 16th, 2005 01:44


All times are GMT. The time now is 13:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42