...

View Full Version : Javascript stopped working



chikoppi
06-26-2006, 08:51 PM
I'm working on a site:

http://users.rcn.com/chikoppi/belvedere2006/test02.html

I've got the markup (html 4.01 transitional) and CSS to validate. However, after passing validation my swapimage scripts stopped working altogether. Clicking on the little page icons should cause the main photo to swap.

Here's the script from the head:



<script language="JavaScript" type="text/javascipt">
<!--
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_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_findObj(n, d) { //v3.0
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); 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>


...and here's the script from the html:



<table cellspacing="0">

<tr>
<td id="mainphoto">
<img src="images/p_01.jpg" width="500" height="300" alt="image" name="mainphoto">
</td>
</tr>

<tr><td height="10"></td></tr>

<tr>
<td id="middlebar">
<table width="500" cellspacing="0">
<tr>
<td width="70" height="40"><img src="images/g_middleleft.gif" width="70" height="40" alt="image"></td>
<td width="430" height="40">
<table width="230" cellspacing="0" align="right">
<tr>
<td height="40" width="50"><img src="images/g_mid_change.gif" width="50" height="40" alt="image"></td>
<td width="20"><img src="images/g_mid_page_on.gif" width="20" height="40" alt="image" name="pageicon01" onClick="MM_swapImage('pageicon01','','images/g_mid_page_on.gif','pageicon02','','images/g_mid_page_off.gif','pageicon03','','images/g_mid_page_off.gif','pageicon04','','images/g_mid_page_off.gif','pageicon05','','images/g_mid_page_off.gif','pageicon06','','images/g_mid_page_off.gif','mainphoto','','images/p_01.jpg',1)"></td>
<td width="20"><img src="images/g_mid_page_off.gif" width="20" height="40" alt="image" name="pageicon02" onClick="MM_swapImage('pageicon01','','images/g_mid_page_off.gif','pageicon02','','images/g_mid_page_on.gif','pageicon03','','images/g_mid_page_off.gif','pageicon04','','images/g_mid_page_off.gif','pageicon05','','images/g_mid_page_off.gif','pageicon06','','images/g_mid_page_off.gif','mainphoto','','images/p_02.jpg',1)"></td>
<td width="20"><img src="images/g_mid_page_off.gif" width="20" height="40" alt="image" name="pageicon03" onClick="MM_swapImage('pageicon01','','images/g_mid_page_off.gif','pageicon02','','images/g_mid_page_off.gif','pageicon03','','images/g_mid_page_on.gif','pageicon04','','images/g_mid_page_off.gif','pageicon05','','images/g_mid_page_off.gif','pageicon06','','images/g_mid_page_off.gif','mainphoto','','images/p_03.jpg',1)"></td>
<td width="20"><img src="images/g_mid_page_off.gif" width="20" height="40" alt="image" name="pageicon04" onClick="MM_swapImage('pageicon01','','images/g_mid_page_off.gif','pageicon02','','images/g_mid_page_off.gif','pageicon03','','images/g_mid_page_off.gif','pageicon04','','images/g_mid_page_on.gif','pageicon05','','images/g_mid_page_off.gif','pageicon06','','images/g_mid_page_off.gif','mainphoto','','images/p_04.jpg',1)"></td>
<td width="20"><img src="images/g_mid_page_off.gif" width="20" height="40" alt="image" name="pageicon05" onClick="MM_swapImage('pageicon01','','images/g_mid_page_off.gif','pageicon02','','images/g_mid_page_off.gif','pageicon03','','images/g_mid_page_off.gif','pageicon04','','images/g_mid_page_off.gif','pageicon05','','images/g_mid_page_on.gif','pageicon06','','images/g_mid_page_off.gif','mainphoto','','images/p_05.jpg',1)"></td>
<td width="20"><img src="images/g_mid_page_off.gif" width="20" height="40" alt="image" name="pageicon06" onClick="MM_swapImage('pageicon01','','images/g_mid_page_off.gif','pageicon02','','images/g_mid_page_off.gif','pageicon03','','images/g_mid_page_off.gif','pageicon04','','images/g_mid_page_off.gif','pageicon05','','images/g_mid_page_off.gif','pageicon06','','images/g_mid_page_on.gif','mainphoto','','images/p_06.jpg',1)"></td>
<td width="60"><img src="images/g_mid_view.gif" width="60" height="40" alt="image"></td>
</tr>
</table>
</td>
</tr>
</table>



I'm all thumbs when it comes to Java. Any ideas?

Mongus
06-26-2006, 08:55 PM
Try using a JavaScript comment before the HTML comment inside of the script that defines the MM functions:

//<!--

chikoppi
06-26-2006, 09:02 PM
Wow, thanks for the fast reply!

Could you be more specific? I'm not sure exactly what you mean.

vwphillips
06-26-2006, 09:05 PM
<script language="JavaScript" type="text/javascript">
<!--


notice the r in script

Mongus
06-26-2006, 09:07 PM
I found the real problem. :)

There's a typo in the script tag in addition to what I posted before. Just change

<script language="JavaScript" type="text/javascipt">
<!--
function MM_preloadImages() { //v3.0
to

<script language="JavaScript" type="text/javascript">
//<!--
function MM_preloadImages() { //v3.0

chikoppi
06-26-2006, 09:10 PM
(sigh.) Man, is my face red. I went looking for some obscure problem, not a spelling error.

Thanks for your help and your sharp eyes on this one!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum