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 Coder
    Join Date
    Apr 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    posting 2 java scripts on one page

    I have a page: http://www.sunelectricsystems.com/Co...nd-mounted.htm
    http://www.sunelectricsystems.com/style1.css
    http://www.sunelectricsystems.com/drop_down.js

    Obviously having 2 #nav ID's is invalid code. I am trying to find a way to have two drop downs on the same page. One for the top menu, and one for the bottom menu.

    I have tried to change the getElementById to getElementByClass, and the corresponding nav variable in the style sheet. This works for FireFox and IE 7, but not IE 6

    The next solution I thought of was to make 2 java scripts and ID's, one for each menu (e.g.: #nav for drop_down, and #nav-again for drop_down2). Problem is, I don't know how to tell the page to run both drop_down.js and drop_down2.js on the same page. I have tried a bunch of ways to tell it to run both scripts, with no luck.

    This:
    <script type="text/javascript" src="../drop_down.js"></script>
    <script type="text/javascript" src="../drop_down2.js"></script>

    Allows only the top script to run.

    Is there a way I can tell IE 6 to run either drop_down or drop_down2, depending on the variable?

    Or is there a way I can get IE 6.0 to accept getElementByClass?

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,794
    Thanks
    19
    Thanked 156 Times in 147 Posts
    I'm not really sure what you are trying to do, but it sounds like conditional comments would help here...

    You generally shouldn't rely on JS to detect the browser type...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    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
    Try this
    Code:
    // JavaScript Document
    startList = function()
    {
        if (document.all&&document.getElementById)
        {
            navRoot = document.getElementsByTagName('ul');
            for(j=0;j<navRoot.length;j++)
            {
                if(navRoot[j].className == 'nav')
                {
                    for (i=0; i<navRoot[j].childNodes.length; i++)
                    {
                        node = navRoot.childNodes[i];
                        if (node.nodeName=="LI")
                        {
                            node.onmouseover=function()
                            {
                                this.className+=" over";
                            }
                            node.onmouseout=function()
                            {
                                this.className=this.className.replace(" over", "");
                            }
                        }
                    }
                }
            }
        }
    }
    window.onload=startList;
    Be sure to get rid of the ids and give them classes of nav and make sure to change your CSS as well to match the classes.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    New Coder
    Join Date
    Apr 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IE 6.0 doesn't work

    The work around code works great in IE 7 and Firefox, but not in IE 6.0. Nothing drops in IE 6 when there are 2 menus on the page, but the new code works in IE 6.0 when there is only 1 menu.

    I am sorry, I am just not good at fixing java.

    I do have conditional comments for a different IE 7.0 bug and the Holly Hack for IE 6 peekaboo bug.

    Thanks

  • #5
    New Coder
    Join Date
    Apr 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Chump2877,

    I have some conditional comments to fix IE 6 and IE 7 bugs, but I can't get the drop down menu's to run together in IE 6 at all. The conditional comment will only work if I can figure out how to either get 2 scripts to run at the same time, or get IE 6 to accept nav as a class. Neighter of which I have been successful at figuring out so far.

    Siggh.

    Thanks

  • #6
    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
    Sorry forgot one part. Try this
    Code:
    // JavaScript Document
    startList = function()
    {
        if (document.all&&document.getElementById)
        {
            navRoot = document.getElementsByTagName('ul');
            for(j=0;j<navRoot.length;j++)
            {
                if(navRoot[j].className == 'nav')
                {
                    for (i=0; i<navRoot[j].childNodes.length; i++)
                    {
                        node = navRoot[j].childNodes[i];
                        if (node.nodeName=="LI")
                        {
                            node.onmouseover=function()
                            {
                                this.className+=" over";
                            }
                            node.onmouseout=function()
                            {
                                this.className=this.className.replace(" over", "");
                            }
                        }
                    }
                }
            }
        }
    }
    window.onload=startList;
    Also java is NOT javascript. They are two totally different languages.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    New Coder
    Join Date
    Apr 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fix worked

    Thank you so much for the addition of that letter [j]. It all works now and I am off to the library to get a JavaScript for dummies book.


  •  

    Posting Permissions

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