getElementById with string and escaped quote problem

B

burfus

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
 
B

Burftone

<input type="hidden" id="testQuote" value="here is a &quot; mark">

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.
 
M

Martin Honnen

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.

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.
 
E

Evertjan.

Martin Honnen wrote on 10 jul 2007 in comp.lang.javascript:
(e-mail address removed) wrote:
<input type="hidden" id="testQuote" value="here is a &quot; mark">

Or even more simple to my eyes:

<input type='hidden' id='testQuote' value='here is a " mark'>
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top