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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with external javascript file including javascript

    I have a site where Im using a drop down menu made with javascript. the problem is after I got it working, I realized this server doesnt allow for SSI. So now, I am trying to put the file into an external .js file where the lines of code can be written with the document.write feature. The problem is that within the document.write lines I have the javascript for the menu that isn't working when I test it. I am a beginner with javascript and I will greatly appreciate anyone can share on how to fix this problem.

    Thanks!

    function displayHeader()
    {
    document.write("<div id='headBox'>");
    document.write(" <img src='images/logo.jpg' id='logo' />");
    document.write("<div id='guideBar'>");
    document.write("<ul>");
    document.write(" <li><a href='1.html' + onMouseOver='hideAll(); showLayer('layer1'); stopTime()' + onMouseOut='startTime();'>1</a></li>");
    document.write(" <li><a href='2' onMouseOver='hideAll(); showLayer('layer2'); stopTime()' onMouseOut='startTime();'>2</a></li>");
    document.write(" <li><a href='3' onMouseOver='hideAll(); showLayer('layer3'); stopTime()' onMouseOut='startTime();'>3</a></li>");
    document.write(" <li><a href='4.html' onMouseOver='hideAll();'>4</a></li>");
    document.write(" <li><a href='index.html' onMouseOver='hideAll();'>HOME</a></li>");
    document.write("</ul>");
    document.write(" <div id='layers'>");
    document.write(" <div id='layer1'>");
    document.write(" <ol>");
    document.write(" <li><a href='11' onMouseOver='stopTime();' onMouseOut='startTime();'>11</a></li>");
    document.write(" <li><a href='12.html' onMouseOver='stopTime();' onMouseOut='startTime();'>12</a></li>");
    document.write(" <li><a href='13.html' onMouseOver='stopTime();' onMouseOut='startTime();'>13</a></li>");
    document.write(" <li><a href='14.html' onMouseOver='stopTime();' onMouseOut='startTime();'>14</a></li>");
    document.write(" <li class='last'><a href='15.html' onMouseOver='stopTime();' onMouseOut='startTime();'>15</a></li>");
    document.write(" </ol>");
    document.write(" </div>");
    document.write(" <div id='layer2'>");
    document.write(" <ol>");
    document.write(" <li><a href='21.html' onMouseOver='stopTime();' onMouseOut='startTime();'>21</a></li>");
    document.write(" <li><a href='22.html' onMouseOver='stopTime();' onMouseOut='startTime();'>22</a></li>");
    document.write(" <li><a href='23.html' onMouseOver='stopTime();' onMouseOut='startTime();'>23</a></li>");
    document.write(" <li><a href='24.html' onMouseOver='stopTime();' onMouseOut='startTime();'>24</a></li>");
    document.write(" <li><a href='25.html' onMouseOver='stopTime();' onMouseOut='startTime();'>25</a></li>");
    document.write(" <li><a href='26.html' onMouseOver='stopTime();' onMouseOut='startTime();'>26</a></li>");
    document.write(" <li class='last'><a href='27.html' onMouseOver='stopTime();' onMouseOut='startTime();'>27</a></li>");
    document.write(" </ol>");
    document.write(" </div>");
    document.write(" <div id='layer3'>");
    document.write(" <ol>");
    document.write(" <li><a href='31.html' onMouseOver='stopTime();' onMouseOut='startTime();'>31</a></li>");
    document.write(" <li><a href='32' onMouseOver='stopTime();' onMouseOut='startTime();'>32</a></li>");
    document.write(" </ol>");
    document.write(" </div>");
    document.write(" </div>");
    document.write(" </div>");
    document.write(" </div>");
    }

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    It is recommended to use double quotes in HTML attributes. So you must use single quotes as Javascript string delimiter. And when you have single quotes inside the string, you need to escape it like this, \'

    Code:
    document.write('<li><a href="1.html" onMouseOver="hideAll(); showLayer(\'layer1\'); stopTime()" onMouseOut="startTime();">1</a></li>');

  • #3
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow, that was easy, thank you very much for the speedy advice!

    maybe a question that I shouldve asked before, is this a reccomended alternative to SSI for including code from an external file?


  •  

    Posting Permissions

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