SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: run time errors

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2000
    Location
    England
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi I have a very simple js rollover nav bar which is giving me probs.. It used to work fine but as I have changed the site I am wondering if I have messed up part of the js code ?

    Can anyone take a look through it please.. many thanks..

    BTW this code is NOT in the head... does it have to be ?

    <script language=JavaScript>
    <!--
    if(document.images) {

    var img1on = new Image();
    img1on.src = 'images/nav/homeon.gif';
    var img2on = new Image();
    img2on.src = 'images/nav/sitemapon.gif';
    var img3on = new Image();
    img3on.src = 'images/nav/abouton.gif';
    var img4on = new Image();
    img4on.src = 'images/nav/advertiseon.gif';
    var img5on = new Image();
    img5on.src = 'images/nav/contacton.gif';





    var img1off = new Image();
    img1off.src = 'images/nav/homeoff.gif';
    var img2off = new Image();
    img2off.src = 'images/nav/sitemapoff.gif';
    var img3off = new Image();
    img3off.src = 'images/nav/aboutoff.gif';
    var img4off = new Image();
    img4off.src = 'images/nav/advertiseoff.gif';
    var img5off = new Image();
    img5off.src = 'images/nav/contactoff.gif';



    }
    function imgOn(imgName) {
    if (document.images) {
    document[imgName].src = eval(imgName + 'on.src;');
    }
    }

    function imgOff(imgName) {
    if (document.images) {
    document[imgName].src = eval(imgName + 'off.src;');
    }
    }
    //-->
    </script>

    AND HERE IS THE NAV BAR ITSELF..

    <!-- java nav bar -->
    <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
    <TR>
    <TD>
    <a href="index.php" onMouseOver="imgOn('img1')" onMouseOut="imgOff('img1')"><IMG SRC="images/nav/homeoff.gif" WIDTH=47 HEIGHT=32 border=0 name=img1></a></TD>
    <TD>
    <IMG SRC="images/nav/spacer1.gif" WIDTH=8 HEIGHT=32 border=0></a></TD>
    <TD>
    <a href="sitemap.php" onMouseOver="imgOn('img2')" onMouseOut="imgOff('img2')"><IMG SRC="images/nav/sitemapoff.gif" WIDTH=73 HEIGHT=32 border=0 name=img2></a></TD>
    <TD>
    <IMG SRC="images/nav/spacer2.gif" WIDTH=7 HEIGHT=32 border=0></a></TD>
    <TD>
    <a href="about.php" onMouseOver="imgOn('img3')" onMouseOut="imgOff('img3')"><IMG SRC="images/nav/aboutoff.gif" WIDTH=59 HEIGHT=32 border=0 name=img3></a></TD>
    <TD>
    <IMG SRC="images/nav/spacer3.gif" WIDTH=6 HEIGHT=32 border=0></a></TD>
    <TD>
    <a href="advertise.php" onMouseOver="imgOn('img4')" onMouseOut="imgOff('img4')"><IMG SRC="images/nav/advertiseoff.gif" WIDTH=94 HEIGHT=32 border=0 name=img4></a></TD>
    <TD>
    <IMG SRC="images/nav/spacer4.gif" WIDTH=10 HEIGHT=32 border=0></a></TD>
    <TD>
    <a href="contact.php" onMouseOver="imgOn('img5')" onMouseOut="imgOff('img5')"><IMG SRC="images/nav/contactoff.gif" WIDTH=75 HEIGHT=32 border=0 name=img5></a></TD>

    </TR>
    </TABLE>

    <!-- end of java nav bar-->

    thanks so much...
    Wannabebig Bodybuilding
    Wannabebig Bodybuilding Forums - Wanna be bigger and stronger?
    At Large Nutrition - nutritional supplements

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2000
    Location
    England
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    seems I have this sorted now.. the index page javascript was not laid out properly and was in a wordwrap style layout..

    Could this cause this ?
    Wannabebig Bodybuilding
    Wannabebig Bodybuilding Forums - Wanna be bigger and stronger?
    At Large Nutrition - nutritional supplements

  3. #3
    SitePoint Member
    Join Date
    Sep 2000
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly is your problem you are having with this code? If your browser is not preloading the images and when you move your mouse over the image, the browser downloads the img everytime you do then I would suggest making an onload(preload()) function so that you can have the images prloaded.

    But other than that I am not sure what you mean.

  4. #4
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Cloughie
    seems I have this sorted now.. the index page javascript was not laid out properly and was in a wordwrap style layout..

    Could this cause this ?
    Wordwrapping per se will not cause a problem; however, JavaScript in general is probably best done in a plain text editor -- so you don't accidentally wind up with "no-see-um" formatting characters stuck in the code.

    JavaScript is fairly forgiving, but in some cases, having everything on one line is critical. Arbitrarily splitting material within the parentheses carrying the arguments of a function or the parameters of a method across two or more lines, for instance, may well cause the code to fail.


  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI Cloughie,

    Glad it's up and running now

    As etLux said, wordWrap in and of itself shouldn't have been the cause of the problem. If the program you used places 'soft' carriage returns, however, it is a horse of a different color. For example, I have cut&pasted code from Word documents that included 'invisible' codes that caused errors and required being retyped. If you want a good, inexpensive (free), non-Notepad editor -- Globalscape's cuteHTML.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  6. #6
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a little off to the left, but definitely related to the problem that started this thread.

    One should also take caution when copying script code from HTML pages, in that it may contain extraneous characters that will cause problems when pasted into your HTML code.

    Though most providers of code snippets are careful to put the code in proper form for copying -- or provide it within plain-text textarea boxes -- there are plenty that are not so careful...

    A good habit to develop is copying the code into NotePad first; then from NotePad into your page.

    This will effectively strip off all but the plain-text characters.



Bookmarks

Posting Permissions

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