www.webdeveloper.com
Results 1 to 2 of 2

Thread: javascript rollover buttons for multiple instances

  1. #1
    Join Date
    May 2009
    Posts
    4

    javascript rollover buttons for multiple instances

    Hey

    I have a page that has two buttons, repeated about 100 times. It's for a song, to preview or download. The script I used works, but only when I have one instance of it in the file. The minute I have two, it doesn't work. Short of creating id's for every instant (code would be massive!) is there a way for each new instance to point to the same rollover code?

    Code:
    <HEAD> 
    <SCRIPT language="JavaScript">
    <!--
    
      if (document.images)
       {
         pic1on= new Image(100,25);
         pic1on.src="shoes2.gif";  
    
         pic1off= new Image(100,25);
         pic1off.src="shoes1.gif";
       }
    
    function lightup(imgName)
     {
       if (document.images)
        {
          imgOn=eval(imgName + "on.src");
          document[imgName].src= imgOn;
        }
     }
    
    function turnoff(imgName)
     {
       if (document.images)
        {
          imgOff=eval(imgName + "off.src");
          document[imgName].src= imgOff;
        }
     }
    
    //-->
    </SCRIPT>
    </HEAD>
    Html looks like this:

    Code:
    <A HREF="index.html" onMouseover="lightup('pic1')" onMouseout="turnoff('pic1')">
    <IMG SRC="../images/shoes1.gif" name="pic1" width="100" height="25" border="0"></A>
    Source/Example can be found here:
    http://www.pageresource.com/jscript/jhover.htm

    I had this custom tailored with my images, but I've been going back and forth between CSS/JS to see what warrants the best result. All I want to do, is be able to change the image when you hover over it, and have 100 or more of the same button on the site.

    Thanks!

  2. #2
    Join Date
    May 2009
    Posts
    4
    Soo... any thoughts? I just wanna know how to do rollover buttons with javascript, and have more than one buton on the stage without having to repeat the code 100 times. There has to be an easier way lol

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles