1

I have made the rollover buttons of my website's navigation in dreamveaver cs4. The image swap function works fine in Chrome & firefox browsers, but in IE9, the swapped picture is shown in two cells on the right side of each one that I roll my mouse over.

I'm new in web designing and I would be glad if anybody could help to fix this problem.

enter code here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function showmenu(elmnt)
{
document.getElementById(elmnt).style.visibility="visible";
}
function hidemenu(elmnt)
{
document.getElementById(elmnt).style.visibility="hidden";
}
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>

<style type="text/css">
<!--

body{;margin-top: 2px;}
a{color:#FFF;text-decoration:none;font:Tahoma, Geneva, sans-serif}
a:hover{color:#FFF}
td.menu{background:#F90; text-align:center;}
table.menu
{
    width:inherit;
font-size:100%;
position:absolute;
visibility:hidden;
}
-->
</style></head>

<body onload="MM_preloadImages('EXCELNET/Home2.png','EXCELNET/About2.png','EXCELNET/Services2.png','EXCELNET/Products2.png','EXCELNET/Contactus2.png','EXCELNET/websms2.png','Pictures/Home2.png','Pictures/About2.png','Pictures/Services2.png','Pictures/Products2.png','Pictures/Contact2.png','Pictures/websms2.png')">
<table border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2"></td>
  </tr>
  <tr>
    <td align="center" valign="top"><table border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="2" colspan="7"></td>
      </tr>
      <tr>
        <td><img src="Pictures/Excelnet Logo.png" width="72" height="25" /></td>
        <td><a href="Home.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('2','','Pictures/Home2.png',1)"><img src="Pictures/Home1.png" name="2" width="140" height="25" border="0" id="2" /></a></td>
        <td><a href="About.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('3','','Pictures/About2.png',1)"><img src="Pictures/About1.png" name="3" width="140" height="25" border="0" id="3" /></a></td>
        <td width="140" onmouseover="showmenu('services')" onmouseout="hidemenu('services')"><a href="Services.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('4','','Pictures/Services2.png',1)"><img src="Pictures/Services1.png" name="4" width="140" height="25" border="0" id="4" /></a><br>
        <table class="menu" id="services" width="120">
   <tr><td class="menu"><a href="/html/default.asp">HTML</a></td></tr>
   <tr><td class="menu"><a href="/css/default.asp">CSS</a></td></tr>
   <tr><td class="menu"><a href="/xml/default.asp">XML</a></td></tr>
   <tr><td class="menu"><a href="/xsl/default.asp">XSL</a></td></tr>
   </table>
   </td>
        <td><a href="Products.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('5','','Pictures/Products2.png',1)"><img src="Pictures/Products1.png" name="5" width="140" height="25" border="0" id="5" /></a></td>
        <td><a href="Contacts.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('6','','Pictures/Contact2.png',1)"><img src="Pictures/Contact1.png" name="6" width="140" height="25" border="0" id="6" /></a></td>
        <td><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('8','','Pictures/websms2.png',1)"><img src="Pictures/websms1.png" name="8" width="140" height="25" border="0" id="8" /></a></td>
      </tr>
    </table></td>
    <td rowspan="3" align="center" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td height="5" align="center" valign="top"></td>
  </tr>
  <tr>
    <td align="center" valign="top"><img src="Pictures/Desktop Computer2.jpg" alt="" width="870" height="379" /></td>
  </tr>
  <tr>
    <td height="5" colspan="2"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="865" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">&copy;2012 EXCELNET SYSTEM</font> &nbsp;&nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">|</font> &nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">Terms & Conditions </font>&nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">|</font> &nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">About </font>&nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">|</font> &nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">Contacts </font>&nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">| </font>&nbsp;&nbsp;<font face="Verdana, Geneva, sans-serif" color="#F37214" size="2pt">Feedback</font></td>
  </tr>
</table></td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
  • With this code, all the image locations are broken, so it might be difficult to solve. Is it possible for you to create a working example, perhaps on [jsFiddle](http://jsfiddle.net)? – andyb Oct 09 '12 at 09:12
  • 1
    These MM_ routines are from the dark ages (with explicit support for Netscape 4 and IE 4, both of which are as dead as browsers can get). I'd strongly recommend throwing them all away and starting with modern coding standards. – Quentin Oct 09 '12 at 13:00
  • Does dreamweaver put the scripts back in if you delete them and try to edit the page? Agree with @Quentin ... try using modern alternatives. – Amitd Oct 09 '12 at 14:47

2 Answers2

0

The problem is that you have used numeric values for your ID attributes. If you prepend a letter then your rollovers will work. Here is some more information about HTML ID attributes: https://stackoverflow.com/a/79022/1622684

Community
  • 1
  • 1
robC
  • 2,592
  • 1
  • 23
  • 28
  • So is it that IE follows the above rule , while Chrome && FF dont ?? or is that statement invalid for latter two? – Amitd Oct 09 '12 at 14:21
  • 1
    @Amitd it's just down to this particular implementation which is quite archaic. For IE the DOM element is referenced using the document.all collection rather than retrieved via document.getElementById(). So document.all[id] resolves to the element at that index. – robC Oct 09 '12 at 14:53
  • ah thanks .. Also does x=d[n] and x=d.all[n] do they evaluate to the same element? – Amitd Oct 09 '12 at 15:07
  • The first expression is something internal to the function - 'd' can be supplied as an argument, to provide an object other than document within which to look up the id. So in this case, no, there is no entry at document[1]. – robC Oct 09 '12 at 15:54
  • Thank you very much for the help. it really worked. I changed the values to a, b, c, d, e, f and it works fine in all IE, Chrome and Firefox. – SeniorShahriyar Oct 10 '12 at 02:41
  • I encountered another problem in IE with the same code after correcting the ID values. it also existed before changing the ID values. the problem is that when I mouse-out the tab (Services) downwards and mouse-over the sub-menu, the sub-menu disappears and the mouse pointer don't get a chance to reach the third and fourth link. thank you for the help – SeniorShahriyar Oct 10 '12 at 04:31
  • Ask a new question - this time try making an example on [jsfiddle.net](http://jsfiddle.net/) – robC Oct 10 '12 at 10:29
-1

Pls try this ..

Around line ~28, in the function MM_findObj(n, d)

replace the line

if(!(x=d[n])&&d.all) x=d.all[n]; 

with

 if(!(d[n])&&d.all) x=d.all[n];

That should make it work on all browser.
Seems like a typo error to me.
Strange if it wasn't.

Amitd
  • 4,769
  • 8
  • 56
  • 82
  • No. While performing an assignment inside an if statement is often considered to be poor code style, it is syntactically valid. In this case it is attempting to get a value via DOM 0 before trying IE4 specific code. – Quentin Oct 09 '12 at 13:00
  • Also that code is generated by Dreamweaver so is entirely unlikely to be a typo. The MM_ prefix is from the days of Macromedia. – robC Oct 09 '12 at 13:06