Forum Moderators: open
I have a drop-down menu script that, within a page, generates the content of the drop-downs by cycling through an array of variables - and those variables are in an exterior js script.
That is, within my page, I have something like this (I have simplified the code):
<script language="JavaScript" src="../data.js"></script>
<script language="javascript1.2">
<!--
for (w=0; w < 4; w++) {
document.write("<div id=submenu>");
for (j =1; j < 4; j++) {
menu_item = menuData[w][j][1];
document.write("<a href=\"" + menu_item + "\">" + menuData[w][j][0] + "</a><br>");
}
document.write("</div>\n");
}
//-->
</script>
The array menuData is declared and filled in the exterior file data.js
In IE, this works fine locally and on-line. In Firefox, the script works on my local machine, but not on-line.
Any ideas here?
Thanks!
1) Before calling document.write() call document.open()
2) Use single quotes.
3) Escape closing tags.
4) Explicitly declare all variables.
5) Remove language attrib and use type="text/javascript"
e.g.
<script type="text/javascript">
<!--
var menu_item;
document.open();
for (var w = 0; w < 4; w++) {
document.write('<div id=submenu>');
for (var j = 1; j < 4; j++) {
menu_item = menuData[w][j][1];
document.write('<a href="' + menu_item + '">' + menuData[w][j][0] + '<\/a><br>');
}
document.write('<\/div>\n');
}
//-->
</script>
You should try opening a console window (under the Tools menu in Firefox) this will display javascript errors (if any).
You should also ensure that both your html and CSS code validate (but most CSS validation warnings are trivial).
The possibility also exists that a page has been cached wrongly. I always use F5 in Opera to clear server caching issues. You can then use Ctrl-F5 in Firefox.
Kaled.