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

    Please help!! what am I DOING WRONG!!

    Hi there... my first post and i'm asking for help

    I'm working on a menu for a website I'm working on and I can't get the button mouseOver effect to work. Only the first button works. Any ideas as to what I might have done wrong?? I'm very new to Javascript and I'm SUPER noob!!

    Ok here's my script:
    Code:
    <Script>
    button1up = new Image; button1up.src = "images/home.gif";
    button1down = new Image; button1down.src = "images/home_up.gif";
    button2up = new Image; button2up.src = "images/products.gif";
    button2down = new Image; button2down.src = "images/products_up.gif";
    button3up = new Image; button3up.src = "images/promotions.gif";
    button3down = new Image; button3down.src = "images/promotions_up.gif";
    button4up = new Image; button4up.src = "images/contactus.gif";
    button4down = new Image; button4down.src = "images/contactus_up.gif";
    button5up = new Image; button5up.src = "images/warranty.gif";
    button5down = new Image; button5down.src = "images/warranty_up.gif";
    
    //MouseOver
    function MouseOverRoutine(ButtonName)
    {
    if (ButtonName=="button1")
    {document.button1.src = button1down.src;}
    }
    {
    if (ButtonName=="button2")
    {document.button2.src = button2down.src;}
    }
    {
    if (ButtonName=="button3")
    {document.button3.src = button3down.src;}
    }
    {
    if (ButtonName=="button4")
    {document.button4.src = button4down.src;}
    }
    {
    if (ButtonName=="button5")
    {document.button5.src = button5down.src;}
    }
    //MouseOut
    function MouseOutRoutine(ButtonName)
    {
    if (ButtonName=="button1")
    {document.button1.src = button1up.src;}
    }
    {
    if (ButtonName=="button2")
    {document.button2.src = button2up.src;}
    }
    {
    if (ButtonName=="button3")
    {document.button3.src = button3up.src;}
    }
    {
    if (ButtonName=="button4")
    {document.button4.src = button4up.src;}
    }
    {
    if (ButtonName=="button5")
    {document.button5.src = button5up.src;}
    }
    
    </script>
    Here's my buttons:
    Code:
    <a href="main.html" onmouseOver="MouseOverRoutine('button1')" onmouseOut="MouseOutRoutine('button1')" target="content">
    <Img Src="images/home.gif" name="button1" border="0" ></a>
    
    <a href="products.html" onmouseOver="MouseOverRoutine('button2')" onmouseOut="MouseOutRoutine('button2')" target="content">
    <Img Src="images/products.gif" name="button2" border="0" ></a>
    
    <a href="promotions.html" onmouseOver="MouseOverRoutine('button3')" onmouseOut="MouseOutRoutine('button3')" target="content">
    <Img Src="images/promotions.gif" name="button3" border="0" ></a>
    
    <a href="contactus.html" onmouseOver="MouseOverRoutine('button4')" onmouseOut="MouseOutRoutine('button4')" target="content">
    <Img Src="images/contactus.gif" name="button4" border="0" ></a>
    
    <a href="warranty.html" onmouseOver="MouseOverRoutine('button5')" onmouseOut="MouseOutRoutine('button5')" target="content">
    <Img Src="images/warranty.gif" name="button5" border="0" ></a>
    Thank you so much for your help!!
    Last edited by suicidalkatt; 09-01-2007 at 08:08 AM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You have to many curly brackets. Make sure they match up.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I changed it to this.. now all but the last button works

    Code:
    function MouseOverRoutine(ButtonName)
    {
    if (ButtonName=="button1")
    {document.button1.src = button1down.src;}
    if (ButtonName=="button2")
    {document.button2.src = button2down.src;}
    if (ButtonName=="button3")
    {document.button3.src = button3down.src;}
    if (ButtonName=="button4")
    {document.button4.src = button4down.src;}
    if (ButtonName=="button5")
    {document.button5.src = button5down.src;}
    }
    function MouseOutRoutine(ButtonName)
    {
    if (ButtonName=="button1")
    {document.button1.src = button1up.src;}
    if (ButtonName=="button2")
    {document.button2.src = button2up.src;}
    if (ButtonName=="button3")
    {document.button3.src = button3up.src;}
    if (ButtonName=="button4")
    {document.button4.src = button4up.src;}
    if (ButtonName=="button5")
    {document.button5.src = button5up.src;}
    }

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Its actually new Image() not new Image, other than that it should work unless the path to the image is wrong.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nvm my code is working fine now... weird...

    http://bulbstar.com/test/test

  • #6
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by suicidalkatt View Post
    nvm my code is working fine now... weird...

    http://bulbstar.com/test/test
    Today's expected standard is for buttons to be 'sticky' to indicate the current selection. This can be done with or without frames.

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Its actually new Image() not new Image, other than that it should work unless the path to the image is wrong.
    Actually, the parentheses are only needed if you want to send arguments to the constructor. Using new SomeConstructor; is entirely legal, and there is not a single browser hosted ECMAScript engine that fails to support it correctly.

    You could argue it's bad style, however...
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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