What am I doing wrong with this javascript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dannykilla
    Senior Member
    • Feb 2008
    • 165
    • 3.7.x

    What am I doing wrong with this javascript?

    Hi,

    I am trying to do a ImageRollover with this Javascript which you can see here:

    Make the image change when a mouse cursor hovers over images on your web page (ie, image rollovers or mouseovers)


    and here is my code (don't laugh, n00b here) and this is not working so can anyone point me in the right direction?

    Code:
    <a href="http://www.xxxxxxxxxx.co.uk"
    onMouseover="buttondown('homebuttondown')"
    onMouseout="buttonup('homebutton')">
    <img src="http://www.xxxxxxxx.co.uk/images/homebutton.png" name="Home" border="0" />
    </a>
    
    <script language="JavaScript" type="text/javascript">
    <!--
    if (document.images) {
    homebuttonup ="buttonup"('homebutton.png');
    homebuttonup.src = "http://www.xxxxxxxxx.co.uk/images/homebutton.png" ;
    homebuttondown ="buttondown"('homebuttondown.png') ;
    homebuttondown.src = "http://www.xxxxxxxxxxx.co.uk/images/homebuttondown.png" ;
    
    }
    function buttondown(homebuttondown.png)
    {
    if (document.images) {
    document[ buttonname ].src = eval( buttonname + "down.src" );
    }
    }
    function buttonup (homebutton.png)
    {
    if (document.images) {
    document[ buttonname ].src = eval( buttonname + "up.src" );
    }
    }
    // -->
    </script>
    Thanks
    Danny
    Last edited by Dannykilla; Tue 2 Sep '08, 1:25pm.
  • Yves R.
    vBulletin QA
    • Nov 2003
    • 3860
    • 5.6.X

    #2
    And with this?
    HTML Code:
    <a href="http://www.xxxxxxxxxx.co.uk" onmouseover="buttondown('homebutton')" onmouseout="buttonup('homebutton')">
    <img src="http://www.xxxxxxxx.co.uk/images/homebutton.png" name="homebutton" border="0" />
    </a>
    
    <script type="text/javascript">
    <!--
    if (document.images)
    {
        homebuttonup = new Image();
        homebuttonup.src = "http://www.xxxxxxxxx.co.uk/images/homebutton.png" ;
        homebuttondown = new Image();
        homebuttondown.src = "http://www.xxxxxxxxxxx.co.uk/images/homebuttondown.png" ;
    }
    
    function buttondown(buttonname)
    {
        if (document.images)
        {
            document[ buttonname ].src = eval( buttonname + "down.src" );
        }
    }
    
    function buttonup(buttonname)
    {
        if (document.images)
        {
            document[ buttonname ].src = eval( buttonname + "up.src" );
        }
    }
    // -->
    </script>
    This is not necessary to edit in javascript functions, edit only these 2 lines:
    Code:
    homebuttonup.src = "http://www.xxxxxxxxx.co.uk/images/homebutton.png" ;
    homebuttondown.src = "http://www.xxxxxxxxx.co.uk/images/homebuttondown.png" ;
    Check the URL link. In the <img> tag, you can see name="homebutton". And in the <a> tag, you have onmouseover="buttondown('homebutton')" onmouseout="buttonup('homebutton')". The "homebutton' text must be the same for these 3 parts (name="", onmouseover="" and onmouseout="").

    vBulletin QA - vBulletin Support French - Lead Project Tools developer

    Next release? Soon(tm)

    Comment

    • Dannykilla
      Senior Member
      • Feb 2008
      • 165
      • 3.7.x

      #3
      Got it sorted Thanks m8

      Dan

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...