Knowledgebase

Problem with Textarea, shows encoded htmls in decoded form

Posted by wmac, 02-14-2010, 09:22 AM
Hello I have a strange problem with textarea tag. When I load a string which contains encoded html into it, it decodes "encoded htmls" when showing the text. I want the encoded parts to remain encoded. (if I echo it normally and view the source of the page, the encoded html has remained encoded, while in textarea it is being shown decoded). Anyone can help? Thank you very much. - Please see the snapshot of the produced textarea here http://lh4.ggpht.com/_c9uu8FF3DjA/S3.../textarea1.JPG - This one is the html source of the produced page. As you see the code inside textarea tag is encoded but above snapshot shows that htmls are decoded (which I don't want).

Posted by DiegoRBaquero, 02-14-2010, 09:27 AM
Are you sure it is possible to do that? I didn't know if it is. Why don't you try iframe?

Posted by wmac, 02-14-2010, 09:31 AM
I just want to show what I have put in textarea. Why it should not be possible. Why should textarea change something we put inside it. I did not know textarea would change things we put in it! I use textarea because user wants to edit the text!

Posted by wmac, 02-14-2010, 09:38 AM
Let me simplify my question. If I build a simple html page with below code, same problem happens. - Please see the snapshot of the produced textarea here http://lh4.ggpht.com/_c9uu8FF3DjA/S3.../textarea1.JPG

Posted by DiegoRBaquero, 02-14-2010, 10:19 AM
Text area will show the text you put inside it, if you want something like TryIt: http://www.w3schools.com/html/tryit....=tryhtml_basic You will need a more advanced thing.

Posted by wmac, 02-14-2010, 10:38 AM
It doesn't. See the post #4 (which is pure html). It seems it decodes any encoded html by default. The problem is that even in pure html this thing happens. If we do a second time encoding using htmlspecialchars it seems the problem will be solved. But the question is that why the hell html's textarea should decode (and actually change) something that we give to it?

Posted by DiegoRBaquero, 02-14-2010, 10:41 AM
Because is a text area, if you want it decoded, dont add textarea tag, just put the HTML code inside the body tag of your html document. You need this: http://www.w3schools.com/html/default.asp

Posted by wmac, 02-14-2010, 10:54 AM
I guess you do not understand english. I say I don't want it to change whatever I put inside the tag, but IT DECODES AND CHANGES IT!! By the way my HTML book (which I wrote in the year 2000) has been sold almost 250,000 copies.

Posted by mattle, 02-14-2010, 12:27 PM
Well, my guess is that the HTML standard provides for this. If you want a '<' to show up anywhere else on the page, you would use '<', so why not within a text area? Imagine if your content had '' in it. How would the browser know how to interpret that as text, and not an end tag, unless you escape the special characters '</textarea>'? Your solution is to encode the ampersands if you literally want to show '<' displayed...the source should read '&lt;' This is pretty basic stuff...could you post the Amazon link to your book? I'd like to check that out.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
How is EZPZ? (Views: 653)


Language:

Client Login

Email

Password

Remember Me

Search