Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript stopped working

    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:

    Code:
    <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:

    Code:
      <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?
    Last edited by chikoppi; 06-26-2006 at 07:56 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try using a JavaScript comment before the HTML comment inside of the script that defines the MM functions:
    Code:
    //<!--
    Last edited by Mongus; 06-26-2006 at 07:59 PM.

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, thanks for the fast reply!

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

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    <script language="JavaScript" type="text/javascript">
    <!--


    notice the r in script
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    Regular Coder
    Join Date
    Jul 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found the real problem.

    There's a typo in the script tag in addition to what I posted before. Just change
    Code:
    <script language="JavaScript" type="text/javascipt">
    <!--
    function MM_preloadImages() { //v3.0
    to
    Code:
    <script language="JavaScript" type="text/javascript">
    //<!--
    function MM_preloadImages() { //v3.0

  • #6
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    (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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •