View Full Version : encoding/decoding html entity numbers (as opposed to names)

13 Dec 2010, 11:53 AM
I'm trying to populate a textfield with >, < or & characters.

When I send my text off to the database with a > in it, it gets thoroughly scrubbed. When retrieve it again, I get back '&#062'.

I've tried Ext.htmlEncode/Decode, and I tried escape/unescape to no effect.

The following code produces
& #062 ;
& #062 ;

<div id="txt1">&nbsp;</div>
<input type="text" id="txt2"><br>
<input type="text" id="txt3">
character = "&#062;"
document.write("<br>" );
document.getElementById("txt1").innerHTML = character;
document.getElementById("txt2").value = character;
document.getElementById("txt3").value = unescape(character);

13 Dec 2010, 1:40 PM
Well, I don't know if there's a more elegant built-in solution out there, but this works:

I simply call it right before outputting to a field.

replaceSpecialChars: function(inString){
// this only needs to be invoked when populating form fields
if(inString==null) {return null;}
outString = inString.replace(">",">");
outString = outString.replace("<","<");
outString = outString.replace("'","'");
outString = outString.replace("&","&");
return outString;