displaying special characters in a <div>

J

Jens Kristensen

I have a problem displaying a divbox containing a html-textarea -
everything works fine with "normal" characters. However, when the
textarea contains special chars like <P> or ' , the box fails to show:

function show(divbox)
{
divbox.style.display='';
}

<div id="divbox" style="display:none" >
<form action="action.php" method="post>
<textarea name ="txt">Text</textarea>
</form>
</div>

If the Text in the textarea is for instance
HERE IS A "QUOTE"

it works fine, while
HERE IS A 'QUOTE'
produces an error

<br>-tags works fine, but
<p>-tags doesn't

Hmmm - hope someone can help...

:eek:)
Jens
 
J

Jens Kristensen

Thank you for your answers - but it still don't work.

I try to make it more exact:



I have a hidden layer

<div id="txtform" style="display:none" >

<form action="action.php" method="post">

<textarea name ="txt">Some text including html</textarea>

</form>

</div>

(The reason for having text inside the textarea is, that the user should be
able to get data out from a MySQL-database and edit it in the textarea. The
in/output from the textarea is supposed to be html - it is a part of a page
for people who want to design and print out their own labels.)


Here is the function, which, when activated, is supposed to show the layer

function show(divbox)
{
divbox.style.display='';
}

The call to the function is
When the function is called, and "normal" text is used inside the textarea,
everything works fine and the layer shows. But characters like ' or </P>
produces an error message, which (translated) says something like "an error
occurred on the page".

Now I have tried with extended chars like &lt; they won't work - they just
display the characters (and even causes an error.)
PHP-addslashes doesn't work either

Anyway - now I have also tried with a plain textarea - and the problem
remains: Even a simple line-shift
like
this
causes problems.

I have absolutely no idea, what could be the problem.
Hope someone can help.

:eek:)
Jens
 
J

Joe Kelsey

I use the following general framework for displaying arbitrary content
in textareas (or any input box really).

<div id="webtarget" style="display: none">
<span class="shaded">Target:<br></span>
<textarea id="web_targetID" name="web_target" cols="78" rows="2"
wrap="hard"
onChange="updateWebMethod (web_list.value, this.value,
'target')">
</textarea>
</div

The code which puts new values in the textarea looks like this:

document.getElementById ("webtarget").style.display = "";
ofrm = document.getElementById ("userform");
ofrm.web_target.value = webtbl.select (0, 'target', null);

Basically, the function webtbl.select picks an arbitrary text value
out of an Object and inserts it into the textarea. The Object data
comes from a MySQL database whose values get sent to the page via a
"hidden" form. This works for arbitrary HTML display in a textarea
without any escaping of content. The textarea displays the data
verbatim. I have a separate button for displaying the contents of the
textarea in a popup window for previewing the content.

/Joe
 
L

Lasse Reichstein Nielsen

Jens Kristensen said:
I have a hidden layer

<div id="txtform" style="display:none" >
<form action="action.php" method="post">
<textarea name ="txt">Some text including html</textarea>
</form>
</div>
Here is the function, which, when activated, is supposed to show the layer

function show(divbox)
{
divbox.style.display='';
}

The call to the function is
<img SRC="buttons/arrow_right.gif" onClick=show(txtform)>

This will probably work in some browsers, but not all. You assume that
the div with id="textbox" is available as a global variable with the
same name. A more compatible version uses
document.getElementById("textbox")
to get the reference, with fallback to document.all for IE 4.

Which browser was this?
Now I have tried with extended chars like &lt; they won't work - they just
display the characters (and even causes an error.)

Cause an error? In the Javascript or on the server?
Anyway - now I have also tried with a plain textarea - and the problem
remains: Even a simple line-shift
like
this
causes problems.

What, exactly is the problem?
It sounds to me like the problem is on the server. I have no problems
with putting HTML tags or entities into the text area in either IE6 or
Opera 7.2.

/L
 
J

Jens Kristensen

I have finally spotted the problem, which was - not the html tags, but the
line-break ,\n, which in another line caused the script to stall.
Removing the \n-code solved the problem.

Thank you for helping me with the problem

:eek:)
Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top