Forum Moderators: open

Message Too Old, No Replies

Javascript Inside document.write

Why won't this work...

         

web_young

9:58 pm on Dec 13, 2005 (gmt 0)

10+ Year Member



Does anybody know why this code won't work? I'm getting an object expected error.


<script language="JavaScript" type="text/javascript">
<!--
if (!exclude) {
if (win&&ie) {document.write('<span id="xawmMenuPathImg_menu" style="position:absolute;top:-50px"><img name="awmMenuPathImg_menu" id="awmMenuPathImg_menu" src="./menu/awmmenupath.gif" alt=""></span><script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]", awmBN="624"; awmAltUrl="";</script><script charset="UTF-8" src="./menu/menu.js" language="JavaScript1.2" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>');}
else if (mac&&saf) {document.write('<span id="xawmMenuPathImg_menu" style="position:absolute;top:-50px"><img name="awmMenuPathImg_menu" id="awmMenuPathImg_menu" src="./menu/awmmenupath.gif" alt=""></span><script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]", awmBN="624"; awmAltUrl="";</script><script charset="UTF-8" src="./menu/menu_safari.js" language="JavaScript1.2" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>');}

}
//-->
</script>

kaled

10:19 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've never tried putting so much in a single write(). Can you write() multiple lines?

Are exclude, win and ie defined?

Have you tested the code before putting it in a write().

You should escape all / chars, thus
document.write('<\/span>');

Kaled.

Fotiman

10:41 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Likewise:

<\/script>

I believe the closing script tag within the string is probably what's causing your problems.

web_young

6:03 pm on Dec 14, 2005 (gmt 0)

10+ Year Member



I've tried the tips you guys gave (thanks for the help, btw). Still gives the same error. So I've tried simplifying it. The code works when it's not in document.write. I've tried the \/ idea, still didn't work. Let me know if you have any other ideas.


<script language="JavaScript" type="text/javascript">
<!--
document.write('<span id="xawmMenuPathImg-davidbraggteam_menu" style="position:absolute;top:-50px"><img name="awmMenuPathImg-davidbraggteam_menu" id="awmMenuPathImg-davidbraggteam_menu" src="./menu/awmmenupath.gif" alt=""></span>');
document.write('<script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]", awmBN="624"; awmAltUrl="";</script>');
document.write('<script charset="UTF-8" src="./menu/davidbraggteam_menu.js" language="JavaScript1.2" type="text/javascript"></script>');
document.write('<script type="text/javascript">awmBuildMenu();</script>');
//-->
</script>

Fotiman

6:35 pm on Dec 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Without seeing the code for building the menu, I don't know what more to tell you. Are you sure that it's not working? I notice you are absolutely positioning the menu with a top of -50px... could it be doing it off the screen? For example, can you remove that -50 setting and see if it works (in which case, it really worked all along, just somewhere off the screen).

Rambo Tribble

1:44 am on Dec 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless your entire document.write is on one line, it must be appended across line breaks with the concatenation operator, as in:

document.write('stuff and such'+
'and further stuff and such'+
'so on and so forth'+
'ad nauseum');

john_k

5:43 am on Dec 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Break up the word "script" in the script tags that are within the document.write:

</sc'+'ript>

and

<sc'+'ript language...