Problem with "onClick" command

  • Thread starter Maria Sudderman
  • Start date
M

Maria Sudderman

I have a prblem with the "onClick" command.
onClick="insert('<a href="URI">', '</a>')">

but this is not correct! why?


Maria
 
D

d d

Maria said:
I have a prblem with the "onClick" command.
onClick="insert('<a href="URI">', '</a>')">
but this is not correct! why?
Maria

Nested quotes. Try this:

onClick="insert('<a href=\"URI\">', '</a>')">

~dd
 
E

Evertjan.

Maria Sudderman wrote on 03 jul 2007 in comp.lang.javascript:
I have a prblem with the "onClick" command.
onClick="insert('<a href="URI">', '</a>')">

but this is not correct! why?

What kind of function is insert(), javascript????
 
D

David Dorward

Nested quotes. Try this:

onClick="insert('<a href=\"URI\">', '</a>')">

The improper nesting is causing problems at the HTML parsing level,
not the JS level.

onclick="insert('<a href=&quot;URI&quot;>', '</a>')">

.... although I would avoid any JavaScript that accepted raw markup as
input.
 
M

Maria Sudderman

thanks, this is the answer

Nested quotes. Try this:

onClick="insert('<a href=\"URI\">', '</a>')">

The improper nesting is causing problems at the HTML parsing level,
not the JS level.

onclick="insert('<a href=&quot;URI&quot;>', '</a>')">

.... although I would avoid any JavaScript that accepted raw markup as
input.
 
R

Richard Cornford

d said:
Nested quotes. Try this:

onClick="insert('<a href=\"URI\">', '</a>')">

In the context of a javascript string literals appearing in an HTML
attribute value it would be safer to transform the inner quotes into
Unicode or hex escape sequences as that renders them unrecognisable to
the HTML parser:-

onclick="insert('<a href=\x22URI\x22>', '</a>')">
-or:-
onclick="insert('<a href=\u0022URI\u0022>', '</a>')">

Richard.
 

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
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top