Newbie:Quote nesting driving me nuts!

Discussion in 'Javascript' started by Patrick, Oct 5, 2003.

  1. Patrick

    Patrick Guest

    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
     
    Patrick, Oct 5, 2003
    #1
    1. Advertising

  2. Patrick

    Patrick Guest

    > 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
     
    Patrick, Oct 7, 2003
    #2
    1. Advertising

  3. Patrick

    Patrick Guest

    > 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
     
    Patrick, Oct 7, 2003
    #3
  4. Patrick

    Patrick Guest

    > 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
     
    Patrick, Oct 8, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bob

    format driving me nuts

    bob, Jul 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    405
  2. Simple Simon

    DateTime driving me nuts

    Simple Simon, Jul 29, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    380
    Simple Simon
    Jul 29, 2003
  3. Marty

    Driving me nuts...

    Marty, Nov 10, 2003, in forum: ASP .Net
    Replies:
    12
    Views:
    709
    Guest
    Nov 12, 2003
  4. Bjoern Wolfgardt

    Impersonate and IIS6 driving me nuts

    Bjoern Wolfgardt, Jan 15, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,154
    bruce barker
    Jan 16, 2004
  5. Simon Harris

    XMLDocument - Driving me nuts!!

    Simon Harris, May 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    333
    Simon Harris
    May 11, 2005
Loading...

Share This Page