rollover problem

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

    rollover problem

    Can someone please tell me what the heck is wrong with my code here on line
    59 and 60. i get an error that says object expected and I have NO
    understanding why. There must be something im overlooking and its really
    irritating because i know how simple this should.
    =============== =============== =============== =============== =============== =
    ======
    <HTML>
    <HEAD>
    <TITLE>MENU</TITLE>
    <SPRIPT LANGUAGE = "JavaScript ">
    <!--

    if (document.image s) {

    img1on = new Image();
    img1on.src = "buttons/button_2_up.gif ";

    img2on = new Image();
    img2on.src = "buttons/button_4_up.gif ";

    img3on = new Image();
    img3on.src = "buttons/button_6_up.gif ";

    img4on = new Image();
    img4on.src = "buttons/button_8_up.gif ";


    img1off = new Image();
    img1off.src = "buttons/button_2_down.g if";

    img2off = new Image();
    img2off.src = "buttons/button_4_down.g if";

    img3off = new Image();
    img3off.src = "buttons/button_6_down.g if";

    img4off = new Image();
    img4off.src = "buttons/button_8_down.g if";
    }

    function imgOn(imgName) {
    if (document.image s) {
    document[imgName].src = eval(imgName + "on.src");
    }
    }

    function imgOff(imgName) {
    if (document.image s) {
    document[imgName].src = eval(imgName + "off.src");
    }
    }
    //-->

    </SCRIPT>

    </HEAD>
    <BODY>

    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="135">

    <TR><IMG SRC="buttons\lo go.gif" width="135" heigth="117" border="0"></TR>
    <TR><IMG SRC="buttons\me nu.gif" border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_1_down.gif " border="0"></TR>

    <TR><A href = "products.h tml" target="main"
    onMouseOver = "imgOn('img 1')" // this is the
    line with the error!!!
    onMouseOut = "imgOff('img1') "> // this one
    too
    <IMG NAME = "img1" border=0 height=27 width=128
    src="buttons\bu tton_2_down.gif "></A></TR>

    <TR><IMG SRC="buttons\bu tton_3_down.gif " border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_4_down.gif " border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_5_down.gif " border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_6_down.gif " border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_7_down.gif " border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_8_down.gif " border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_9_down.gif " border="0"></TR>
    <TR><IMG SRC="buttons\bu tton_10_down.gi f" border="0"></TR>
    </BODY>
    </TABLE>
    </HTML>


  • Lasse Reichstein Nielsen

    #2
    Re: rollover problem

    "Paul Weikel" <weikelp@earthl ink.net> writes:
    [color=blue]
    > Can someone please tell me what the heck is wrong with my code here on line
    > 59 and 60. i get an error that says object expected and I have NO
    > understanding why. There must be something im overlooking and its really
    > irritating because i know how simple this should.[/color]

    I'll just give it the full treatment :)

    Remember a DOCTYPE to set the browser into standards mode.[color=blue]
    > <HTML>
    > <HEAD>
    > <TITLE>MENU</TITLE>
    > <SPRIPT LANGUAGE = "JavaScript ">[/color]
    ^
    This P shoud be a C.
    Also, the language attribute is depreacted and the type attribute is
    required. Change this to
    <script type="text/javascript">
    [color=blue]
    > <!--[/color]

    HTML comments are not necessary in Javascript code.
    [color=blue]
    > if (document.image s) {[/color]

    Which currently used browsers don't have document.images ?
    Why do you test for it, if you don't use it? (even though you should
    use it!)
    [color=blue]
    > function imgOn(imgName) {
    > if (document.image s) {
    > document[imgName].src = eval(imgName + "on.src");[/color]

    Bad code. It assumes the image is available as a property of the
    document element. If you test for document.images , you might as well
    use it.

    You use eval to access a variable/object property. That is never
    necessary, and should be avoided.

    Change to:
    document.images[imgName].src = window[imgName+"on"].src;

    (Instead of a lot of global variables, you could have made just
    one pointing to an object, and then stored the Image elements in it.
    [color=blue]
    > document[imgName].src = eval(imgName + "off.src");[/color]

    As above.
    [color=blue]
    > //-->[/color]
    As for opening comments.
    [color=blue]
    > <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="135">[/color]

    Consider using CSS for controlling display. It is more powerful
    than HTML attributes.
    [color=blue]
    > <TR><A href = "products.h tml" target="main"
    > onMouseOver = "imgOn('img 1')" // this is the
    > line with the error!!!
    > onMouseOut = "imgOff('img1') "> // this one
    > too[/color]

    Both errors probablt come from the "spript" tag. The functions are
    simply not defined.

    To find errors like this, you can use an HTML validator like
    <URL:http://validator.w3.or g/>. (It requires adding a DOCTYPE
    declaration, but you should do that anyway).

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...