Newbie:Quote nesting driving me nuts!

P

Patrick

Hi

I have been on this little problem for quite a while and i have enough
trying to figure it out.I escaped from the left from the right and in
between, using single and double quotes to no avail, it's got me beat.
I am trying to add the link "color" to a child window (Done) and when
i place my mouse on color, the child window color changes (Not done).
It's annoying me because it looks like an easy fix.

Here is the code:

<SCRIPT TYPE="Text/javascript">
NewWindow = window.open('New.html','',"WIDTH=300 HEIGHTS='200'");
NewWindow.document.write("<A
HREF='#'onMouseOver=\"NewWindow.document.bgColor='#ff0000'\">Color</A>")//not
working
</SCRIPT>

Thanks a lot

Patrick
(e-mail address removed)
 
P

Patrick

First problem, and maybe a typo, is you have no space between HREF="#" and
onMouseOver. The simplest way to "escape" something is to write it as if you
were hardcoding it, use ", and then wrap it with ' and you are finished. If the
code contains ', then escape it.

NewWindow.document.write('<A
HREF="#' onMouseOver="NewWindow.document.bgColor=\'#ff0000\'">Color</a>');

The second problem is you are making the bgColor change harder than it is. If
the link is in the NewWindow, then document.bgColor will suffice, since its
already running from that window. The line then becomes:

NewWindow.document.write('<A
HREF="#' onMouseOver="document.bgColor=\' #ff0000\' ">Color</a>');

Hi Randy

Thanks a lot for taking the time to help me.Unfortunately your fix
does not seem to work.I use the coda editor which highlights parts of
the code when something is wrong and onMouseOver is highlighted along
with the closing </A> tag (I pasted your corrected code in my editor.)
I also do not understand your escaping technique (i.e. HREF="#').
I hope you can help some more.

Thanks a lot for your time

Patrick
 
P

Patrick

The second problem is you are making the bgColor change harder than it is. If
the link is in the NewWindow, then document.bgColor will suffice, since its
already running from that window. The line then becomes:

NewWindow.document.write('<A
HREF="#' onMouseOver="document.bgColor=\' #ff0000\' ">Color</a>');

Randy

Disregard my previous post, i figured it out.You had a typo in the
HREF="#'.
My quote nesting must have been good several times originally, what
was really wrong was the NewWindow being referenced twice.Thanks so
much for pointing this out.I still find it strange that referencing
the NewWindow a second time by mistake would prevent the code from
working but anyway i know to be carefull now in the future.

Thanks again

Patrick
 
P

Patrick

The reason you can't reference it the second time is that in the new window,
there is no reference given to newWindow, so its an undefined variable. And you
are writing the link to the new window, so, it doesn't work. Glad you got it
fixed though.

Randy

I got this too.It makes so much sense now!

Thanks so much

Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top