getElementById with string and escaped quote problem

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

  1. burfus

    burfus Guest

    Hi,
    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 \

    <HTML>
    <BODY>

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

    <SCRIPT Type="text/javascript">
    <!--
    alert(document.getElementById("testQuote").value);
    //-->
    </SCRIPT>

    </body>
    </html>

    Any Ideas?
    TIA!
    Burftone
     
    burfus, Jul 10, 2007
    #1
    1. Advertisements

  2. <input type="hidden" id="testQuote" value="here is a &quot; mark">
     
    Martin Honnen, Jul 10, 2007
    #2
    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
    #3
  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
    mark"
    is junk the parser ignores.
     
    Martin Honnen, Jul 10, 2007
    #4
  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
    #5
    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.