getElementById with string and escaped quote problem

Discussion in 'Javascript' started by burfus, Jul 10, 2007.

  1. burfus

    burfus Guest

    I'm stumped on escaping a double quote when retrieving the value using
    getElementById. Here is a sample where the quote is escaped but the
    alert box only shows: Here is a \


    <form name="testForm" action="#" method="post">
    <INPUT type="hidden" id="testQuote" value="here is a \" mark">

    <SCRIPT Type="text/javascript">


    Any Ideas?
    burfus, Jul 10, 2007
    1. Advertisements

  2. <input type="hidden" id="testQuote" value="here is a &quot; mark">
    Martin Honnen, Jul 10, 2007
    1. Advertisements

  3. burfus

    Burftone Guest

    Thanks Martin, I'll do a string replace and that will work. The
    elements are populated by strings from a database where users have
    used double quotes for inches. I thought I could just addslashes with
    PHP and have it work OK, but the escape character isn't recognized
    when javascript picks up the string from the input element.

    Thanks Again.
    Burftone, Jul 10, 2007
  4. That has nothing at all to do with JavaScript. The HTML parser when
    parsing the value of the attribute named value looks for a closing quote
    so if you do
    value="here is a \" mark"
    ^ ^
    then the parser finds those two quotes and consequently the value of
    that attribute is "here is a \" and the remaining
    is junk the parser ignores.
    Martin Honnen, Jul 10, 2007
  5. burfus

    Evertjan. Guest

    Martin Honnen wrote on 10 jul 2007 in comp.lang.javascript:
    Or even more simple to my eyes:

    <input type='hidden' id='testQuote' value='here is a " mark'>
    Evertjan., Jul 10, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.