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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Problem with roll-over image code

    Hi, I'm having a problem getting one of my image rollovers to work, what confuses me is that the other image works fine, I'm trying to get this to
    work for an assignment

    here's the javascript:
    Code:
    rollImage = new Array()
    	
    	for(i = 0; i < 12; i++){
    		
    		rollImage[i] = new Image(85,85);
    	}
    	
    
     
      rollImage[0].src = "images/narav2.jpg";
      rollImage[1].src = "images/narav3.jpg";
      rollImage[2].src = "images/sasuke-avatar-118.jpg";
      rollImage[3].src = "images/sasuke.jpg";
      
      
    
      function swapNar(img){       //this works fine
        document.nar11.src = rollImage[img].src;
        return true;
      }
    
      function returnNar(img){     //this function works fine as well
        document.nar11.src = rollImage[img].src; 
        return true;
      }
    
      function swapSas(img){                    //this function not working
    	document.sasim.src = rollImage(img).src;
        return true;
      }
      
      function returnSas(img){                         //this function also not working
    	document.sasim.src = rollImage(img).src;
        return true;
      }

    Here's the HTML:

    Code:
    <tr>
     <td height="60">
     <img src="images/narav2.jpg" name="nar11" width="85" height="85" border="0" id="nar11"/> 
     </td>
        
     <td>
     
     <a href="naruto.html" onMouseover = "swapNar(1)" onMouseout = "returnNar(0)"> Naruto </a>
    
     </td>
    </tr>
    
    <!-- When I mouse over the above link the image rolls over as expected,
          the bottom link doesn't work as expected and I can't see what I'm
          doing wrong -->
    
    
    
    <tr>
    <td height="60">
    <img src="images/sasuke-avatar-118.jpg" name="sasim" width="85" height="85" border="0" id="sasim"/>
    </td>
    
    <td>
    
    <a href="sasuke.html" onMouseout= "swapSas(3)" onMouseover= "returnSas(2)"> Sasuke </a>
    
    </td>
    
    
    </tr>

    I can't see what the problem is with the returnSas and swapSas functions,
    I'm still a noob at this and would really appreciate some assistance,
    thanks in advance
    Last edited by Cha1; 09-04-2010 at 07:33 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    document.sasim.src = rollImage(img).src;

    should be

    document.sasim.src = rollImage[img].src; // square brackets


    BTW, the time to say "thanks" is afterwards, not beforehand which gives the - doubtless unintended - impression that you take other people's voluntary unpaid assistance and expertise for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.



    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • Users who have thanked Philip M for this post:

    Cha1 (09-04-2010)

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks very much, I don't believe I didn't see that, I have also clicked "thank user for post".

    Sorry about the 'thank you in advance' thing, won't do it again


  •  

    Posting Permissions

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