Need help with unterminated string constant ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    Need help with unterminated string constant ...

    Hi, does anyone know why this:

    <a onclick="insert atcaret(window. opener.document .formname.field name,'<td
    class="header"> ')">text</a>

    returns a "Unterminat ed 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.


  • Don Sutter

    #2
    Re: Need help with unterminated string constant ...

    Does the escape character "\" around your "header" help any?

    <a
    onclick="insert atcaret(window. opener.document .formname.field name,'<td
    class=\"header\ ">')">text</a>



    "Jeff" <jmox@mail.co m> wrote in message
    news:gVzmc.3322 7$IG1.1710273@a ttbi_s04...[color=blue]
    > Hi, does anyone know why this:
    >
    > <a[/color]
    onclick="insert atcaret(window. opener.document .formname.field name,'<td[color=blue]
    > class="header"> ')">text</a>
    >
    > returns a "Unterminat ed String Constant" error message in IE 6.0 but[/color]
    if[color=blue]
    > I take out the double quotes around header it does not? I need[/color]
    double[color=blue]
    > quotes around header, I thought this was possible in javascript so[/color]
    long[color=blue]
    > as the pair of double quotes is surrounded by a pair of single[/color]
    quotes.[color=blue]
    >
    >[/color]


    Comment

    • Jeff

      #3
      Re: Need help with unterminated string constant ...

      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:DYzmc.1003 7$Hs1.4711@news read2.news.pas. earthlink.net.. .[color=blue]
      > Does the escape character "\" around your "header" help any?
      >
      > <a
      > onclick="insert atcaret(window. opener.document .formname.field name,'<td
      > class=\"header\ ">')">text</a>
      >
      >
      >
      > "Jeff" <jmox@mail.co m> wrote in message
      > news:gVzmc.3322 7$IG1.1710273@a ttbi_s04...[color=green]
      > > Hi, does anyone know why this:
      > >
      > > <a[/color]
      > onclick="insert atcaret(window. opener.document .formname.field name,'<td[color=green]
      > > class="header"> ')">text</a>
      > >
      > > returns a "Unterminat ed String Constant" error message in IE 6.0 but[/color]
      > if[color=green]
      > > I take out the double quotes around header it does not? I need[/color]
      > double[color=green]
      > > quotes around header, I thought this was possible in javascript so[/color]
      > long[color=green]
      > > as the pair of double quotes is surrounded by a pair of single[/color]
      > quotes.[color=green]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Don Sutter

        #4
        Re: Need help with unterminated string constant ...

        Actually, you have double quotes surrounded by single quotes which in
        turn are surrounded by double quotes. Hummm....

        "Jeff" <jmox@mail.co m> wrote in message
        news:icAmc.3300 6$TD4.5426899@a ttbi_s01...[color=blue]
        > Thanks for the idea, but putting an escape character ( \ ) before[/color]
        each[color=blue]
        > quote around header does not help in this case.
        >
        > "Don Sutter" <no@way.com> wrote in message
        > news:DYzmc.1003 7$Hs1.4711@news read2.news.pas. earthlink.net.. .[color=green]
        > > Does the escape character "\" around your "header" help any?
        > >
        > > <a
        > >[/color][/color]
        onclick="insert atcaret(window. opener.document .formname.field name,'<td[color=blue][color=green]
        > > class=\"header\ ">')">text</a>
        > >
        > >
        > >
        > > "Jeff" <jmox@mail.co m> wrote in message
        > > news:gVzmc.3322 7$IG1.1710273@a ttbi_s04...[color=darkred]
        > > > Hi, does anyone know why this:
        > > >
        > > > <a[/color]
        > >[/color][/color]
        onclick="insert atcaret(window. opener.document .formname.field name,'<td[color=blue][color=green][color=darkred]
        > > > class="header"> ')">text</a>
        > > >
        > > > returns a "Unterminat ed String Constant" error message in IE 6.0[/color][/color][/color]
        but[color=blue][color=green]
        > > if[color=darkred]
        > > > I take out the double quotes around header it does not? I need[/color]
        > > double[color=darkred]
        > > > quotes around header, I thought this was possible in javascript[/color][/color][/color]
        so[color=blue][color=green]
        > > long[color=darkred]
        > > > as the pair of double quotes is surrounded by a pair of single[/color]
        > > quotes.[color=darkred]
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Michael Winter

          #5
          Re: Need help with unterminated string constant ...

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

          [fixed top-post]
          [color=blue]
          > "Jeff" <jmox@mail.co m> wrote in message
          > news:gVzmc.3322 7$IG1.1710273@a ttbi_s04...
          >[color=green]
          >> Hi, does anyone know why this:
          >>
          >> <a onclick="insert atcaret(window. opener.document .formname.field name,
          >> '<td class="header"> ')">text</a>
          >>
          >> returns a "Unterminat ed String Constant" error message in IE 6.0 but if
          >> I take out the double quotes around header it does not?[/color][/color]

          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.
          [color=blue][color=green]
          >> 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.[/color][/color]

          The same behaviour applies to both HTML and JavaScript.
          [color=blue]
          > Does the escape character "\" around your "header" help any?[/color]

          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;hea der&quot;>')">t ext</a>

          Mike

          --
          Michael Winter
          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

          Comment

          • Michael Winter

            #6
            Re: Need help with unterminated string constant ...

            On Fri, 07 May 2004 00:05:33 GMT, Michael Winter
            <M.Winter@bluey onder.co.invali d> wrote:

            [snip]
            [color=blue]
            > To solve it, do what you should always do with restricted characters in
            > HTML: use a character entity.[/color]

            I forgot: the angle brackets are also restricted. You should use character
            entities for them too.
            [color=blue]
            > <a ... onclick="[...],'<td class=&quot;hea der&quot;>')">t ext</a>[/color]

            ....should be

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

            Mike

            --
            Michael Winter
            M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

            Comment

            • Richard Cornford

              #7
              Re: Need help with unterminated string constant ...

              Don Sutter wrote:

              Please do not top post on comp.lang.javas cript. See the FAQ for details
              of appropriate positing style for this group.
              [color=blue]
              > Does the escape character "\" around your "header" help any?
              >
              > <a
              > onclick="insert atcaret(window. opener.document .formname.field name,'<td
              > class=\"header\ ">')">text</a>[/color]
              <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="insert atcaret(
              window.opener.d ocument.formnam e.fieldname,
              '<td class=\x22heade r\x22>'
              );"

              Richard.


              Comment

              Working...