in reply to HTML Problem getting entities into a textarea

I believe you'll have to 'double escape' the html escape code for it to show up correctly in the browser's textarea. For example if you wanted '>' to show in the textarea you'd have to write it as '>'. That way when the browser interprets the code it will only replace the '&' with '&' leaving '>' and not '>'.

Incidentally, in order to print this out correctly I have to triple escape the code. Talk about confusing!

-caedes

  • Comment on Re: HTML Problem getting entities into a textarea

Replies are listed 'Best First'.
Re: Re: HTML Problem getting entities into a textarea
by muad33b (Acolyte) on Apr 18, 2003 at 21:00 UTC

    Thanks, but if you try it like I suggested, you'll see the dilema - here is the problem:

    I want &lt; to show up as-is, since that is what the user typed when the document was created. If I have them double-escape (or really escape the & with &amp;) then when I save the text, and then display it later (on a technote display page that drops the html in a table cell) it will show as &lt; and not as <

    The problem is that most tags inside the textarea tag are NOT interpreted, but the following IS:

    <textarea>&lt;property key="smtpHost"        value=""/&gt;</textarea>

    Basically, I think that this is a bug in the textarea tag for html - any other ideas?

    TIA again, Jeff

      I want &lt; to show up as-is, since that is what the user typed when the document was created.

      If the user literaly typed '&' 'l' 't' ';', then to prevent this from being corrupted when you spit the text back out into a textarea, you're going to need to escape the '&'. This isn't an HTML bug, though it's not the most documented aspect of HTML that you'll find.

        Know what? This problem doesn't seem to exist here in perl monks. It's the same basic idea as here. Folks are entering html in textareas. But if I put this in

        <property key="smtpHost" value=""/>

        it is saved as I typed it - with the escapes, and viewed as I want it - escapes interpreted, and is brought back up in the edit textarea with the escapes intact; uninterpreted.

        What am I missing here? I need so save with all &s escaped to &amp;, and then unescape them to & when I display, but dump it when I edit, or vice versa?