...

View Full Version : need help with external javascript file including javascript



mathematics
03-16-2005, 10:46 AM
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>");
}

glenngv
03-16-2005, 10:52 AM
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, \'



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

mathematics
03-16-2005, 11:50 AM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum