Reputation: 43477
I have a textarea used for comments that loads the contents of a div when a link is pressed, putting those contents in the displayed textarea.
Everything worked fine until I introduced a way to display interpoints (I'm talking about the ·
entity). These display fine in the div, but the problem is they also display as dots in the actual textarea, which I don't want. I want them to display as {*}
in the textarea, since this is the string that gets converted to ·
on the server side.
This is the function I use to handle the display of tags:
function HtmlDecode(str)
{
var ta = document.createElement("textarea");
ta.innerHTML = str.replace(/</g, "<").replace(/>/g, ">").replace(/·/g, "{*}");
toReturn = ta.value;
ta = null;
return toReturn.replace(/<br\s*\/?>/mg, "\n");
}
I output the textarea like this:
anotherDiv.innerHTML = '<textarea ...>' + HtmlDecode(div.innerHTML) + '</textarea>';
What I don't understand is why if I change the /·/g
replace with /asdf/g
for example, any asdf
will get replaced just fine.
Bottom line: how can I make my textarea display {*}
instead of an actual interpoint?
Upvotes: 0
Views: 2180
Reputation: 1592
What about .replace(/·/g, "{*}")
instead of .replace(/·/g, "{*}");
?
Upvotes: 1