sorry ... total noob rollover debug

Discussion in 'Javascript' started by Matt, Jul 18, 2005.

  1. Matt

    Matt Guest

    i know more-or-less zero about javascript, but my client wants a
    rollover and he created this code, which doesn't work. All comments are
    appreciated.

    1. the tag:
    <td align="center" width="66" nowrap="nowrap"
    background="/work/phc1.10/images/layout/main_nav_bg.gif">
    <a href="http://localhost/work/phc1.10/index.php?page=homecare"
    onmouseover="imgSwap('','gnav_hc_on','gnav_hc_on')"
    onmouseout="imgSwap('','gnav_hc_off','gnav_hc_off')">
    <img name="gnav_hc_off"
    src="/work/phc1.10/images/layout/gnav/gnav_hc_off.gif" border="0"
    alt="Homecare" width="66" height="14" /></a>
    </td>


    2. the function:

    function imgSwap(layer,imgName,imgObj) {
    var layer;
    var imgName;
    var imgObj;
    glayer = layer;
    gimgName = imgName;
    gimgObj = imgObj;
    if(document.images) {
    //NN 4.x DOM
    if(document.layers && layer != "") {
    eval('document.' + layer + '.document.images["' + imgName + '"].src =
    ' + imgObj + '.src');
    }
    //NN6 Gecko subroutine
    else if((objClient.application == "nn") && (objClient.version >= 5)) {
    imgSwapTimeOut();
    }
    else {
    document.images[imgName].src = eval(imgObj + ".src");
    }
    }
    }
    //NN Gecko subroutine
    function imgSwapTimeOut() {
    document.images[gimgName].src = eval(gimgObj + ".src");
    }
     
    Matt, Jul 18, 2005
    #1
    1. Advertising

  2. Matt

    Matt Guest

    extra info, btw I'm a different Matt

    the "bug" is that the swap doesn't seem to occur. I have the javascript
    console open and no error appears there. My dev box is Lx/firefox, but I
    looked at it in IE as well and it's no good there either.

    Thanks again.
     
    Matt, Jul 18, 2005
    #2
    1. Advertising

  3. Matt

    alu Guest

    "Matt" <> wrote
    > i know more-or-less zero about javascript, but my client wants a
    > rollover and he created this code, which doesn't work. All comments are
    > appreciated.
    >
    > 1. the tag:
    > <td align="center" width="66" nowrap="nowrap"
    > background="/work/phc1.10/images/layout/main_nav_bg.gif">
    > <a href="http://localhost/work/phc1.10/index.php?page=homecare"
    > onmouseover="imgSwap('','gnav_hc_on','gnav_hc_on')"
    > onmouseout="imgSwap('','gnav_hc_off','gnav_hc_off')">
    > <img name="gnav_hc_off"
    > src="/work/phc1.10/images/layout/gnav/gnav_hc_off.gif" border="0"
    > alt="Homecare" width="66" height="14" /></a>
    > </td>
    >
    >
    > 2. the function:
    >
    > function imgSwap(layer,imgName,imgObj) {
    > var layer;
    > var imgName;
    > var imgObj;
    > glayer = layer;
    > gimgName = imgName;
    > gimgObj = imgObj;
    > if(document.images) {
    > //NN 4.x DOM
    > if(document.layers && layer != "") {
    > eval('document.' + layer + '.document.images["' + imgName + '"].src =
    > ' + imgObj + '.src');
    > }
    > //NN6 Gecko subroutine
    > else if((objClient.application == "nn") && (objClient.version >= 5)) {
    > imgSwapTimeOut();
    > }
    > else {
    > document.images[imgName].src = eval(imgObj + ".src");
    > }
    > }
    > }
    > //NN Gecko subroutine
    > function imgSwapTimeOut() {
    > document.images[gimgName].src = eval(gimgObj + ".src");
    > }




    There are probably a million better written / less complex rollover scripts
    out there, do you really need to use this one? If so, for starters, he
    hasn't
    set any image src's.
    Secondly, the mouseover imgSwap('','gnav_hc_on','gnav_hc_on')"
    should likely be imgSwap('','gnav_hc_off','gnav_hc_on')" since there is no
    image named 'gnav_hc_on'.
    If this is for a single rollover, (or perhaps in any case) junk the script,
    not worth the trouble. Not to mention the <td> tag.
    -alu
     
    alu, Jul 18, 2005
    #3
  4. Matt

    ASM Guest

    Matt wrote:
    > i know more-or-less zero about javascript, but my client wants a
    > rollover and he created this code, which doesn't work. All comments are
    > appreciated.


    Your client use DW ? and its MacroMerdum ? and that doesn't work ?
    Tremendous !

    Try to tell him there is better way using css to get a rollover.
    i.e :
    http://perso.wanadoo.fr/stephane.moriaux/truc/bouton_3_etats_css.htm
    that doesn't need pre-loading of images and is much cheaper

    there are very simple ways to set a rollover

    the easiest but the worst :

    <a href="somePage.htm" target="_blank"
    onmouseover="ir=document.images('foo'); ir.src="img_over.gif;"
    onmouseout="ir.src="img_out.gif">
    <img name="foo" src="img_out.gif" border=0></a>


    better :

    <script type="text/javascript"><!-- // script to put in header

    // sometimes the following pre-loads images (NC4, IE4 to FF1.0.4, IE6)
    if(document.images) {
    But_01 = new Image(); But_01.src = 'buttons/I_01.gif'; // normal
    But_01o = new Image(); But_01o.src = 'buttons/O_01.gif'; // over

    But_02 = new Image(); But_02.src = 'buttons/I_01.gif'; // normal
    But_02o = new Image(); But_02o.src = 'buttons/O_01.gif'; // over

    // and so on for each button
    }

    function di(name,id) { if(document.images)
    eval(document.images(name).src = id+'.src'); }

    // --></script>
    </head>
    <body>
    <a href="somePage.htm"
    onmouseover="di('Ig_01','But_01o');
    onmouseover="di('Ig_01','But_01');>
    <img name="Ig_01" src="buttons/I_01.gif" border=0></a>
    <a href="someOtherPage.htm"
    onmouseover="di('Ig_02','But_02o');
    onmouseover="di('Ig_02','But_02');>
    <img name="Ig_02" src="buttons/I_02.gif" border=0></a>

    > 1. the tag:
    > <td align="center" width="66" nowrap="nowrap"
    > background="/work/phc1.10/images/layout/main_nav_bg.gif">
    > <a href="http://localhost/work/phc1.10/index.php?page=homecare"
    > onmouseover="imgSwap('','gnav_hc_on','gnav_hc_on')"
    > onmouseout="imgSwap('','gnav_hc_off','gnav_hc_off')">
    > <img name="gnav_hc_off"
    > src="/work/phc1.10/images/layout/gnav/gnav_hc_off.gif" border="0"
    > alt="Homecare" width="66" height="14" /></a>
    > </td>
    >
    >
    > 2. the function:


    ask to DreamWeaver

    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, Jul 18, 2005
    #4
  5. Matt

    Matt Guest

    thanks ... halfway there

    I junked the old script and am getting some functionality with this:

    if (document.images) {
    gnav_ho_up = new Image();
    gnav_ho_up.src = "/work/phc1.10/images/layout/gnav/gnav_ho_off.gif" ;
    gnav_ho_down = new Image() ;
    gnav_ho_down.src = "/work/phc1.10/images/layout/gnav/gnav_ho_on.gif" ;
    }

    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" );
    }
    }


    tag:
    <a href="http://localhost/work/phc1.10/index.php?page=phchome"
    onmouseover="buttondown('gnav_ho')"
    onmouseout="buttonup('gnav_ho')">

    <img name="gnav_ho"
    src="/work/phc1.10/images/layout/gnav/gnav_ho_off.gif" border="0"
    alt="Home" width="100" height="14" /></a>

    problem: it's saying that image can't be found. the reference in the
    <img ...
    tag works -- that image appears. but when you roll over it gets the
    blank box instead of gnav_ho_on.gif

    I've tried inserting all manner of slashes etc. How does one tell
    javascript to use src's relative to the site's root?
     
    Matt, Jul 18, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ArtDent
    Replies:
    3
    Views:
    481
    Josiah Carlson
    Feb 7, 2004
  2. Zach Heath

    Sorry for the NOOB question..

    Zach Heath, Sep 14, 2007, in forum: C Programming
    Replies:
    19
    Views:
    688
    Charlie Gordon
    Sep 18, 2007
  3. Tom Lake

    Total Python Noob

    Tom Lake, Oct 10, 2008, in forum: Python
    Replies:
    3
    Views:
    256
    Tom Lake
    Oct 10, 2008
  4. Adam Chapman

    total noob- call c function from c#

    Adam Chapman, Dec 20, 2008, in forum: C Programming
    Replies:
    7
    Views:
    367
    Kenny McCormack
    Dec 21, 2008
  5. Total NOOB needs java advice

    , Oct 27, 2005, in forum: Javascript
    Replies:
    4
    Views:
    104
    ducky
    Oct 30, 2005
Loading...

Share This Page