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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change text style in a TextArea

Status
Not open for further replies.

RichS

Programmer
Joined
Apr 24, 2000
Messages
380
Location
US
I have a Text Area that allows users to enter text and save it to a database. I need to change the style of only part of the text. The idea is that the user can click a button that fires some JavaScript code that appends a block of text to the TextArea that is a different Font Color and Font Name from the rest of the text in the TextArea. The following is one of my attempts.

Code:
function CodeBlock() {
  var sText;
  var sCodeBlock;
  var oElement;
      
  oElement = frmPosts.all["txtTextArea"];
  sText = oElement.value;  // The text areas current text
      
  sCodeBlock = '<BR><FONT style=&#34;font-family:CourierNew;font-color:Blue;&#34;>Type Formatted Text Here</FONT>';
	      
  sText += sCodeBlock;
  alert("Value: " + sText);
	      
  oElement.value = sText;
		}
This adds the text to the TextArea but the HTML tags are visible in the TextArea rather than the text being formatted. Any ideas how this can be done?

Thanks,
Rich
 
You can't format parts of text in a textbox, it's either all or nothing. One option may be to use something like this:
Code:
<div contenteditable="true" onblur="document.formName.hiddenFieldName.value=this.innerHTML"></div>

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top