By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,967 Members | 815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,967 IT Pros & Developers. It's quick & easy.

Need help with unterminated string constant ...

P: n/a
Hi, does anyone know why this:

<a onclick="insertatcaret(window.opener.document.form name.fieldname,'<td
class="header">')">text</a>

returns a "Unterminated String Constant" error message in IE 6.0 but if
I take out the double quotes around header it does not? I need double
quotes around header, I thought this was possible in javascript so long
as the pair of double quotes is surrounded by a pair of single quotes.
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Does the escape character "\" around your "header" help any?

<a
onclick="insertatcaret(window.opener.document.form name.fieldname,'<td
class=\"header\">')">text</a>

"Jeff" <jm**@mail.com> wrote in message
news:gVzmc.33227$IG1.1710273@attbi_s04...
Hi, does anyone know why this:

<a onclick="insertatcaret(window.opener.document.form name.fieldname,'<td class="header">')">text</a>

returns a "Unterminated String Constant" error message in IE 6.0 but if I take out the double quotes around header it does not? I need double quotes around header, I thought this was possible in javascript so long as the pair of double quotes is surrounded by a pair of single quotes.

Jul 23 '05 #2

P: n/a
Thanks for the idea, but putting an escape character ( \ ) before each
quote around header does not help in this case.

"Don Sutter" <no@way.com> wrote in message
news:DY******************@newsread2.news.pas.earth link.net...
Does the escape character "\" around your "header" help any?

<a
onclick="insertatcaret(window.opener.document.form name.fieldname,'<td
class=\"header\">')">text</a>

"Jeff" <jm**@mail.com> wrote in message
news:gVzmc.33227$IG1.1710273@attbi_s04...
Hi, does anyone know why this:

<a

onclick="insertatcaret(window.opener.document.form name.fieldname,'<td
class="header">')">text</a>

returns a "Unterminated String Constant" error message in IE 6.0 but

if
I take out the double quotes around header it does not? I need

double
quotes around header, I thought this was possible in javascript so

long
as the pair of double quotes is surrounded by a pair of single

quotes.


Jul 23 '05 #3

P: n/a
Actually, you have double quotes surrounded by single quotes which in
turn are surrounded by double quotes. Hummm....

"Jeff" <jm**@mail.com> wrote in message
news:icAmc.33006$TD4.5426899@attbi_s01...
Thanks for the idea, but putting an escape character ( \ ) before each quote around header does not help in this case.

"Don Sutter" <no@way.com> wrote in message
news:DY******************@newsread2.news.pas.earth link.net...
Does the escape character "\" around your "header" help any?

<a
onclick="insertatcaret(window.opener.document.form name.fieldname,'<td
class=\"header\">')">text</a>

"Jeff" <jm**@mail.com> wrote in message
news:gVzmc.33227$IG1.1710273@attbi_s04...
Hi, does anyone know why this:

<a

onclick="insertatcaret(window.opener.document.form name.fieldname,'<td
class="header">')">text</a>

returns a "Unterminated String Constant" error message in IE 6.0

but if
I take out the double quotes around header it does not? I need

double
quotes around header, I thought this was possible in javascript
so long
as the pair of double quotes is surrounded by a pair of single

quotes.



Jul 23 '05 #4

P: n/a
On Thu, 06 May 2004 23:34:59 GMT, Don Sutter <no@way.com> wrote:

[fixed top-post]
"Jeff" <jm**@mail.com> wrote in message
news:gVzmc.33227$IG1.1710273@attbi_s04...
Hi, does anyone know why this:

<a onclick="insertatcaret(window.opener.document.form name.fieldname,
'<td class="header">')">text</a>

returns a "Unterminated String Constant" error message in IE 6.0 but if
I take out the double quotes around header it does not?
Quote nesting only works once. That is

" ' ' "

is fine, but

" ' " " ' "

is not. The latter is interpreted as two separate quoted strings each
containing some spaces and a single apostrophe.
I need double quotes around header, I thought this was possible in
javascript so long as the pair of double quotes is surrounded by a pair
of single quotes.

The same behaviour applies to both HTML and JavaScript.
Does the escape character "\" around your "header" help any?


It shouldn't. The mark-up is operating under HTML's parsing rules, not
JavaScript's. When the HTML parser encounters \", it sees a backslash
followed by a double quote. When the JavaScript parser encounters it, it
sees an escaped double quote. To solve it, do what you should always do
with restricted characters in HTML: use a character entity.

<a ... onclick="[...],'<td class=&quot;header&quot;>')">text</a>

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #5

P: n/a
On Fri, 07 May 2004 00:05:33 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:

[snip]
To solve it, do what you should always do with restricted characters in
HTML: use a character entity.
I forgot: the angle brackets are also restricted. You should use character
entities for them too.
<a ... onclick="[...],'<td class=&quot;header&quot;>')">text</a>


....should be

<a ... onclick="[...],'&lt;td class=&quot;header&quot;&gt;')">

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #6

P: n/a
Don Sutter wrote:

Please do not top post on comp.lang.javascript. See the FAQ for details
of appropriate positing style for this group.
Does the escape character "\" around your "header" help any?

<a
onclick="insertatcaret(window.opener.document.form name.fieldname,'<td
class=\"header\">')">text</a>

<snip>

That will not help as the HTML parser is not aware of javascript escape
sequences and can still see the double quote as part of the page's
source code. It will take the first pair of quotes as delimiting the
string for the onclick attribute.

Instead a javascript hex escape sequence could be used in this context
as that would still result in the double quote in the resulting
javascript string but would be meaningless to the HTML parser:-

onclick="insertatcaret(
window.opener.document.formname.fieldname,
'<td class=\x22header\x22>'
);"

Richard.
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.