Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting child nodes in TextArea

Status
Not open for further replies.

enochsfootwear

Programmer
Aug 11, 2004
25
0
0
US
Hello,
I have a page with a Text area and some links above it that the user clicks to add to the text area, “AND”,”OR”,”NOT”, etc. I’m tying to change the color of the
Text that is added. I ‘ve tried the code below which changes the color of the text that is added but any text that is typed in after that is red, it’s like the </font> tag is not being closed. Here’s there something that I’m missing?

Thanks

Code:
   <script type=”text/javascript>
	Function addKeywork(){
        var newText= document.createTextNode("hello world");
        var newFont = document.createElement("font");
        newFont.style.color = "red";
        newFont.appendChild(newText);
        document.getElementById('t1').appendChild(newFont);
           }
</script>
 
I think you've open a can of worms. Look the other way for this kind of rendering like using div's. appendChild() of any kind of tagged element is fundamentally wrong kind of action. Quirks (or bugs if you like) are wide-spread: not only limited to ie, moz-series has their fair share as well.
 
Thanks for your answer.
Do you mean use a DIV instead of the Text Area? This is an existing project and I really can't change the controls.

Thanks again
 
Yes, that's what I mean. [1] From the practical side, use appendChild() of tagged elements to textarea with the script you sketched above results in different behaviour ie/ff. [2] Even if the project proclaims its own target audience, which is legitimate, that kind of "child" to a textarea is so fundamentally lying outside the html spec (and the quirk itself in ie is sufficient to flag a warning even if you stick to proprietary ie as a program of its own right). [3] The child of a textarea control can only be #PCDATA (that means parsed character data, basically some string with some escape...). That piece of spec seems to me very respectable and of good sense. I wouldn't resort to violence against that bit of the spec. It's up to you, and I don't want to make big noise on this ugly issue neither.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top