FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Nesting Javascript inside javascript

 


thinkfacility
I've been trying to use the document.writeln(''); function to make some navigation links. Recently I found a nice rollover navigation template online for free, and I've been trying to make it work. The code I'm using is:

document.writeln('<div class="nav"><a href="default.htm"

onClick="returnclickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1,

"150px")" onMouseout="delayhidemenu()">Web Design</a> | <a href="default2.htm"

onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1,

"150px")" onMouseout="delayhidemenu()">More Sites</a></div>');

But it's not working, are you not allowed to nest javascript inside of document.writeln's or something like that?
Gushe
why are you making it so difficult? Razz

couldn't just make a link and add all the JavaScript functions there. (I think..)
Just with HTML tags (not with the writeln rubbish Razz)


~Gushe
MrBlueSky
1. Make sure to put the entire document.write statement on one line, without newlines.

2. You can't nest "-delimited strings within other "-delimited strings, so this will not work:

Code:

onMouseover="dropdownmenu(this, event, menu1,"150px")"


Use escaped single quotes instead. The entire statement now will look like this:

Code:

document.writeln('<div class="nav"><a href="default.htm" onClick="returnclickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1, \'150px\')" onMouseout="delayhidemenu()">Web Design</a> | <a href="default2.htm" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1, \'150px\')" onMouseout="delayhidemenu()">More Sites</a></div>');
thinkfacility
Well, if I didn't use the writeln then I'd have to use frames wouldn't I? I'm trying to make it so that I can update the entire navigation area on every page by only changing one file

Ooo...the backslashes did the trick! Very Happy I noticed that the ' marks made the entire thing not show up, so I just removed them...guess I needed them after all! Thanks a bunch MrBlueSky!
Agent ME
If you want to update multiple pages by editing one file, you don't want to use javascript, but PHP includes.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.