Masiar
Masiar

Reputation: 21352

Forcing a carriage return in textarea

I would like to start a textarea with inside a text that starts some line under the first line. Doing something like:

var myText = '\r \r \r HELLO';

doesn't work: HELLO is written on the first line, while

var myText = 'HELLO \r \r \r HELLO2';

puts correctly HELLO2 after HELLO. This means that \r is correct, but it doesn't work at the beginning of the textarea.

Any suggestions?

Upvotes: 10

Views: 44865

Answers (8)

Luc Verheecke
Luc Verheecke

Reputation: 1

Bonjour, I soved this problem by adding
instead of \r\n. I suggest to check css attributes of textarea.

Please take note I won't return to see if there are question about mine text.

Upvotes: 0

selbie
selbie

Reputation: 104589

Don't use \r, use \n

Example: var myText = '\n \n \n HELLO';

Upvotes: 5

Rick Presley
Rick Presley

Reputation: 161

Try inserting 
 into the text area.

Upvotes: 16

Aaron
Aaron

Reputation: 1083

In PHP I had to make sure to use double quotes instead of single.

$var1 = 'Test1 above /n/n Test below'; //will not work
$var2 = "Test2 above /n/n Test below"; //will work
echo = "<textarea>$var1</textarea><br /><textarea>$var2</textarea>";

Upvotes: 2

josh3736
josh3736

Reputation: 145152

What browser and/or OS are you using? In my quick test, both \r and \n yield the same (correct) result on Windows in IE 8, Firefox 3.6, and Chrome 9.

 

<textarea rows="5" id="r"></textarea>
<textarea rows="5" id="n"></textarea>

 

$(function() {
    $('#r').val('\r\r\rHello');
    $('#n').val('\n\n\nHello');
});

Upvotes: 0

JonWillis
JonWillis

Reputation: 3147

If you are using .net.

Then do

Var myText = "Hello" + Enviroment.NewLine + "Hello2";

However if your using something else, i.e. Java, web languages then I advise you try /n followed by /r. I have had to use "/n/r" to get the result I wanted, after the /r was being ignored.

Upvotes: 0

Carlos Valenzuela
Carlos Valenzuela

Reputation: 834

"\r" is to return to the begining of the line the, i forgot its name, i think is the cursor. But what you need is "\n" for a new line

Upvotes: 0

parrker9
parrker9

Reputation: 958

Have you tried to put space or &nbsp; before the "\r"?

Upvotes: 5

Related Questions