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 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down Cure for JavaScript (multiple script in one document) insanity.

    Hey,

    Good old javascript is beginning to drive me insane, I am seeking a cure for the following code problem:

    Symptoms: The code that I am about to include on this post does not work as I would like it to. It seems that I have a choice, I can either have my dynamic menu (see the head section of the following code) or I can have my text scroller (see body section of code). If I omit the scroller then the menu works however I cannot get the menu and scroller script to cooperate. I don't know why this is the case, only that it is. I have searched the document trying to find variables that may have the same name (but belong to both scripts) however this does not appear to be the problem. If anybody can point out to me why these scripts won't work together then I will be greatly appreciative. Thanks for your time.

    <html>
    <head>
    <title> Fern Gully Stamps </title>
    <style type="text/css">
    caption
    {
    font-weight: bold;
    color: #8d340a;
    }
    a:visited
    {
    color: #0e5a03;
    }
    a:hover
    {
    color: #8d340a;
    }
    .info_message
    {
    color: #000051;
    font-family: Georgia, Sans-Serif;
    font-size: 18px;
    }
    .tab_row
    {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: bold;
    }
    .tab_bord
    {
    border-width: 2px 2px 2px 2px;
    border-style: solid;
    border-color: #8d340a;
    }
    </style>
    <script language="JavaScript" src="navcond.js"></script>
    <script language="JavaScript">

    var myNavBar1 = new NavBar(0);
    var dhtmlMenu;

    //define menu items (first parameter of NavBarMenu specifies main category width, second specifies sub category width in pixels)
    //add more menus simply by adding more "blocks" of same code below

    dhtmlMenu = new NavBarMenu(80, 80);
    dhtmlMenu.addItem(new NavBarMenuItem("Home", ""));
    dhtmlMenu.addItem(new NavBarMenuItem("Home Page", "/Ferngully/index.htm"));
    myNavBar1.addMenu(dhtmlMenu)

    dhtmlMenu = new NavBarMenu(150, 150);
    dhtmlMenu.addItem(new NavBarMenuItem("Company Profile", ""));
    dhtmlMenu.addItem(new NavBarMenuItem("Company Profile", "/Ferngully/files/html/company_profile.htm"));
    myNavBar1.addMenu(dhtmlMenu);

    dhtmlMenu = new NavBarMenu(120, 120);
    dhtmlMenu.addItem(new NavBarMenuItem("Craft Stamps", ""));
    dhtmlMenu.addItem(new NavBarMenuItem("Browse Catalogue", "/Ferngully/files/html/craft_stamps.htm"));
    myNavBar1.addMenu(dhtmlMenu);

    dhtmlMenu = new NavBarMenu(100, 120);
    dhtmlMenu.addItem(new NavBarMenuItem("Business Stamps", ""));
    dhtmlMenu.addItem(new NavBarMenuItem("Self Inkers", "/Ferngully/files/html/business_stamps.htm"));
    dhtmlMenu.addItem(new NavBarMenuItem("Type Sets", "/Ferngully/files/html/type_sets.htm"));
    myNavBar1.addMenu(dhtmlMenu);

    dhtmlMenu = new NavBarMenu(100, 120);
    dhtmlMenu.addItem(new NavBarMenuItem("Scrapbooking", ""));
    dhtmlMenu.addItem(new NavBarMenuItem("Papers", "/Ferngully/files/html/scrapbooking.htm"));
    dhtmlMenu.addItem(new NavBarMenuItem("Frames", "/Ferngully/files/html/frames.htm"));
    myNavBar1.addMenu(dhtmlMenu);

    dhtmlMenu = new NavBarMenu(100, 120);
    dhtmlMenu.addItem(new NavBarMenuItem("Coming Events", ""));
    dhtmlMenu.addItem(new NavBarMenuItem("Classes, Shows & Events", "/Ferngully/files/html/coming_events.htm"));
    myNavBar1.addMenu(dhtmlMenu);

    dhtmlMenu = new NavBarMenu(100, 150);
    dhtmlMenu.addItem(new NavBarMenuItem("Order Forms", ""));
    myNavBar1.addMenu(dhtmlMenu);
    dhtmlMenu.addItem(new NavBarMenuItem("Craft Stamps Order Form", "/Ferngully/files/html/order_form_fg.htm"));
    dhtmlMenu.addItem(new NavBarMenuItem("Business Stamps Order Form", "/Ferngully/files/html/order_form_cv.htm"));

    //set menu colors
    myNavBar1.setColors("#0e5a03", "#DEE302", "#0E5A03", "#DEE302", "#0e5a03", "#DEE302", "#0E5A03", "#ffffff", "#8D340A")

    //uncomment below line to center the menu (valid values are "left", "center", and "right"
    myNavBar1.setAlign("center")

    var fullWidth;

    function init() {

    // Get width of window, need to account for scrollbar width in Netscape.

    fullWidth = getWindowWidth()
    - (isMinNS4 && getWindowHeight() < getPageHeight() ? 16 : 0);

    myNavBar1.resize(fullWidth);
    myNavBar1.create();
    myNavBar1.setzIndex(2);
    //UNCOMMENT BELOW LINE TO MOVE MENU DOWN 50 pixels
    myNavBar1.moveTo(0, 0);
    }
    </script>
    <SCRIPT LANGUAGE="JavaScript">
    function addbookmark()
    {
    bookmarkurl="http://www.ferngullystamps.com"
    bookmarktitle="Welcome To Fern Gully Stamps"
    if (document.all)
    window.external.AddFavorite(bookmarkurl,bookmarktitle)
    }
    // End -->
    </script>
    </head>
    <body background="crinkle.jpg" onload="init()">
    <table width="100%">
    <tr>
    <td><br><br></td>
    </tr>
    <tr align="center">
    <td><img src="heading_1.jpg" hspace="70"></td>
    </tr>
    <tr align="center">
    <td><a href="javascript:addbookmark()"><b>Bookmark This Page</b></a></td>
    </tr>
    </table>
    <table width="100%">
    <tr align="center">
    <td width="50%"><img src="entry.jpg"></td>
    <td width="50%">
    <script language="javaScript">

    /*
    Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
    For full source code, 100's more DHTML scripts, and TOS, visit http://www.dynamicdrive.com
    Credit MUST stay intact
    */

    //Specify the marquee's width (in pixels)
    var marqueewidth="200px"
    //Specify the marquee's height
    var marqueeheight="150px"
    //Specify the marquee's marquee speed (larger is faster 1-10)
    var marqueespeed=2
    //Pause marquee onMousever (0=no. 1=yes)?
    var pauseit=1

    //Specify the marquee's content
    //Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

    var marqueecontent='<font face="Verdana">Thank you for visiting <a href="http://www.dynamicdrive.com">Dynamic Drive.</a><p>If you find this script useful, please consider linking to us by <a href="../link.htm">clicking here.</a><p>Visit our partner <a href="http://javascriptkit.com">JavaScript Kit</a> for JavaScript tutorials.</font>'


    ////NO NEED TO EDIT BELOW THIS LINE////////////

    marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
    var copyspeed=marqueespeed
    var pausespeed=(pauseit==0)? copyspeed: 0
    var iedom=document.all||document.getElementById
    var actualheight=''
    var cross_marquee, ns_marquee

    function populate(){
    if (iedom){
    cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
    cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
    cross_marquee.innerHTML=marqueecontent
    actualheight=cross_marquee.offsetHeight
    }
    else if (document.layers){
    ns_marquee=document.ns_marquee.document.ns_marquee2
    ns_marquee.top=parseInt(marqueeheight)+8
    ns_marquee.document.write(marqueecontent)
    ns_marquee.document.close()
    actualheight=ns_marquee.document.height
    }
    lefttime=setInterval("scrollmarquee()",20)
    }
    window.onload=populate

    function scrollmarquee(){

    if (iedom){
    if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
    cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
    else
    cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
    }
    else if (document.layers){
    if (ns_marquee.top>(actualheight*(-1)+8))
    ns_marquee.top-=copyspeed
    else
    ns_marquee.top=parseInt(marqueeheight)+8
    }
    }

    if (iedom||document.layers){
    with (document){
    if (iedom){
    write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
    write('<div id="iemarquee" style="position:absolute;left:0px;top:0px;width:100%;">')
    write('</div></div>')
    }
    else if (document.layers){
    write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee">')
    write('<layer name="ns_marquee2" width='+marqueewidth+' height='+marqueeheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
    write('</ilayer>')
    }
    }
    }
    </script>
    </td>
    </tr>
    </table>
    <table class="tab_bord" width="100%">
    <caption> Retail and Trade Enquiries </caption>
    <tr>
    <td class="tab_row"> 2/14 Thomas Street, Ferntree Gully, VIC. 3156 </td>
    <td class="tab_row"> Phone: (03) 9753 5094 </td>
    <td class="tab_row"> Fax/ Phone: (03) 9753 5109 </td>
    </tr>
    <tr>
    <td class="tab_row">Email: <a href="mailto: ferngully@iprimus.com.au">ferngully@iprimus.com.au </a></td>
    </tr>
    </table>
    <table width="100%">
    <tr align="center">
    <td><a href="/Ferngully/files/html/under_construction.htm">WebMasters Credits</a></td>
    </tr>
    </table>
    </body>
    </html>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts

    onload conflict

    If you search this forum, you'd find the answer. This type of problem has been asked many times in this forum.
    You have this in your page:

    <body background="crinkle.jpg" onload="init()">
    ...
    window.onload=populate


    Those 2 onloads conflict with each other, the latter cancels the former.

    The solution is to combine them.
    Remove the window.onload line and put it in the body onload.

    <body background="crinkle.jpg" onload="init();populate()">


  •  

    Posting Permissions

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