frequently ask ? : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 21 people (43%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

how can i write a string variable to an existing textarea....and maintain line breaks e.g. \r or \n

Aug 9th, 2001 01:59
Jean-Bernard Valentaten, mur nolan,


As you should know, HTML-tags are not interpreted when nested inside a 
textarea, but escape sequences (like \n) are. So when writing a 
variable to the textarea.value simply insert \n for line break.
function writeToTextarea()
{
  document.getElementById('theNameofyourTextarea').value 
= 'Hello\n\nHow are you doing?'
}
That should work (in IE5+ and NN6 at least).
HTH