Javascript Mouseover Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • richk

    Javascript Mouseover Problem

    For some reason when I add additional buttons a 3rd button and beyond
    i cant get the effect to work and I get errors...I cant understand
    why...

    <SCRIPT LANGUAGE = "javascript "><!--

    if (document.image s) { // Active Images
    img1on = new Image();
    img1on.src = "button1_on.jpg ";

    img2on = new Image();
    img2on.src = "button2_on.jpg ";

    img1off = new Image();
    img1off.src = "button1_off.jp g";

    img2off = new Image();
    img2off.src = "button2_off.jp g"; }

    // Function to 'activate' images.
    function imgOn(imgName) {
    if (document.image s) {
    document[imgName].src = eval(imgName + "on.src");
    }
    }

    // Function to 'deactivate' images.
    function imgOff(imgName) {
    if (document.image s) {
    document[imgName].src = eval(imgName + "off.src");
    }
    }

    // -->
    </SCRIPT>


    <A HREF="page1.htm " onMouseOver="im gOn('img1')"
    onMouseOut="img Off('img1')">
    <IMG NAME="img1" SRC="button1_of f.jpg" ALT="mouseover button"
    HEIGHT="30"
    WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>

    <A HREF="page2.htm " onMouseOver="im gOn('img2')"
    onMouseOut="img Off('img2')">
    <IMG NAME="img2" SRC="button2_of f.jpg" ALT="another mouseover button"
    HEIGHT="30"
    WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
  • Lee

    #2
    Re: Javascript Mouseover Problem

    richk said:[color=blue]
    >
    >For some reason when I add additional buttons a 3rd button and beyond
    >i cant get the effect to work and I get errors...I cant understand
    >why...[/color]

    The code you posted only has 2 buttons (and there is
    at least one typo). Post the code that you want to
    work, but doesn't.

    Comment

    • Dominique

      #3
      Re: Javascript Mouseover Problem


      I try with a third button and I don't see any problem
      I use the following code and it seems to work

      <html><head></head><body>
      <SCRIPT LANGUAGE = "javascript "><!--

      if (document.image s) { // Active Images
      img1on = new Image();
      img1on.src = "button1_on.jpg ";

      img2on = new Image();
      img2on.src = "button2_on.jpg ";

      img3on = new Image();
      img3on.src = "button3_on.jpg ";

      img1off = new Image();
      img1off.src = "button1_off.jp g";

      img2off = new Image();
      img2off.src = "button2_off.jp g";

      img3off = new Image();
      img3off.src = "button3_off.jp g";

      }

      // Function to 'activate' images.
      function imgOn(imgName) {
      if (document.image s) {
      document[imgName].src = eval(imgName + "on.src");
      }
      }

      // Function to 'deactivate' images.
      function imgOff(imgName) {
      if (document.image s) {
      document[imgName].src = eval(imgName + "off.src");
      }
      }

      // -->
      </SCRIPT>


      <A HREF="page1.htm " onMouseOver="im gOn('img1')"
      onMouseOut="img Off('img1')">
      <IMG NAME="img1" SRC="button1_of f.jpg" ALT="mouseover button"
      HEIGHT="30"
      WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
      <br>
      <A HREF="page2.htm " onMouseOver="im gOn('img2')"
      onMouseOut="img Off('img2')">
      <IMG NAME="img2" SRC="button2_of f.jpg" ALT="second mouseover button"
      HEIGHT="30"
      WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
      <br>
      <A HREF="page3.htm " onMouseOver="im gOn('img3')"
      onMouseOut="img Off('img3')">
      <IMG NAME="img3" SRC="button3_of f.jpg" ALT="third mouseover button"
      HEIGHT="30"
      WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
      </body></html>
      --
      Ce message a ete poste via la plateforme Web club-Internet.fr
      This message has been posted by the Web platform club-Internet.fr


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Javascript Mouseover Problem

        Dominique wrote:
        [color=blue]
        > [The usual eval() nonsense testing for the wrong property][/color]

        See
        <http://jibbering.com/faq/#FAQ4_40>
        <http://pointedears.de/scripts/test/whatami>
        and last but not least
        <http://pointedears.de/scripts/test/hoverMe/>

        hoverMe is for free and free software,
        only take heed of the GPLv2 or above.


        HTH

        PointedEars

        Comment

        Working...