From: Xerxes on
Hi,
I have a textarea in my page and its value comes from the database.
The text in the database table contains some html tags like <br />.
However, when the page is rendered I see <br /> instead of line breaks
and view source shows "&lt;br /&gt;". I tries to do a replace in the
js code that assigns the value to textarea but no change.
When I added a breakpoint, at the point of assignment, the value
contained < and > and not &lt; and &gt; Is there anything I can do to
force the html tags to be interpretted and not printed?

document.getElementById('taComments').value =
record.Comment.replace('&lt;', '<').replace('&gt;', '>');

"record.Comment" conatins:
This comment was added manually in the database for testing
purposes.<br />Some other text follows ....
From: Evertjan. on
Xerxes wrote on 26 mei 2010 in comp.lang.javascript:

> Hi,
> I have a textarea in my page and its value comes from the database.
> The text in the database table contains some html tags like <br />.

That is an XML tag, not an HTML one.

> However, when the page is rendered I see <br /> instead of line breaks
> and view source shows "&lt;br /&gt;". I tries to do a replace in the
> js code that assigns the value to textarea but no change.
> When I added a breakpoint, at the point of assignment, the value
> contained < and > and not &lt; and &gt; Is there anything I can do to
> force the html tags to be interpretted and not printed?
>
> document.getElementById('taComments').value =
> record.Comment.replace('&lt;', '<').replace('&gt;', '>');

try:

==========================================

<textarea id='ta'>here</textarea>

<script type='text/javascript'>
var oldT = 'Hello<br />world!';
var newT = oldT.replace('<br />','\n');
document.getElementById('ta').innerHTML = newT;
</script>

==========================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: Xerxes on
On May 26, 11:46 am, "Evertjan." <exjxw.hannivo...(a)interxnl.net>
wrote:
> Xerxes wrote on 26 mei 2010 in comp.lang.javascript:
>
> > Hi,
> > I have a textarea in my page and its value comes from the database.
> > The text in the database table contains some html tags like <br />.
>
> That is an XML tag, not an HTML one.
>
> > However, when the page is rendered I see <br /> instead of line breaks
> > and view source shows "&lt;br /&gt;". I tries to do a replace in the
> > js code that assigns the value to textarea but no change.
> > When I added a breakpoint, at the point of assignment, the value
> > contained < and > and not &lt; and &gt; Is there anything I can do to
> > force the html tags to be interpretted and not printed?
>
> > document.getElementById('taComments').value =
> > record.Comment.replace('&lt;', '<').replace('&gt;', '>');
>
> try:
>
> ==========================================
>
> <textarea id='ta'>here</textarea>
>
> <script type='text/javascript'>
>   var oldT = 'Hello<br />world!';
>   var newT = oldT.replace('<br />','\n');
>   document.getElementById('ta').innerHTML = newT;
> </script>
>
> ==========================================
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Thank you for the reply.
I modified the script as you suggested but it gives me an error when I
change '.value' to '.innerHTML':
htmlfile: unknown runtime error.

When I changed it back to '.value' it kind of works; only the first
instance of <br /> is replaced by '\n' which actually does a line
break. Other <br /> remain unchanged.
From: Evertjan. on
Xerxes wrote on 26 mei 2010 in comp.lang.javascript:

>> � var newT = oldT.replace('<br />','\n');

[please do not quote signatures on usenet]

> Thank you for the reply.
> I modified the script as you suggested but it gives me an error when I
> change '.value' to '.innerHTML':
> htmlfile: unknown runtime error.
>
> When I changed it back to '.value' it kind of works; only the first
> instance of <br /> is replaced by '\n' which actually does a line
> break. Other <br /> remain unchanged.

I am not going to do your work, just point you to a useful direction.

Please readup the specs of javascript replace()
on regex and replace multiple.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: Xerxes on
On May 26, 11:46 am, "Evertjan." <exjxw.hannivo...(a)interxnl.net>
wrote:
> Xerxes wrote on 26 mei 2010 in comp.lang.javascript:
>
> > Hi,
> > I have a textarea in my page and its value comes from the database.
> > The text in the database table contains some html tags like <br />.
>
> That is an XML tag, not an HTML one.
>
> > However, when the page is rendered I see <br /> instead of line breaks
> > and view source shows "&lt;br /&gt;". I tries to do a replace in the
> > js code that assigns the value to textarea but no change.
> > When I added a breakpoint, at the point of assignment, the value
> > contained < and > and not &lt; and &gt; Is there anything I can do to
> > force the html tags to be interpretted and not printed?
>
> > document.getElementById('taComments').value =
> > record.Comment.replace('&lt;', '<').replace('&gt;', '>');
>
> try:
>
> ==========================================
>
> <textarea id='ta'>here</textarea>
>
> <script type='text/javascript'>
>   var oldT = 'Hello<br />world!';
>   var newT = oldT.replace('<br />','\n');
>   document.getElementById('ta').innerHTML = newT;
> </script>
>
> ==========================================
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

I found this piece of code at http://www.bennadel.com/blog/142-Ask-Ben-Javascript-String-Replace-Method.htm.
It allowed me to replace all instances.
Thank you for yoour help.