View Full Version : when changing a value of a textfield how do I make \n show up

08-01-2002, 04:22 PM
when changing a value of a textfield how do I make \n show up instead of make a line break?

08-01-2002, 04:25 PM
Do you mean textarea? Can you give us an example of what you are trying to do?

08-01-2002, 04:33 PM
Perhaps you mean something like this:

<textarea cols="40" rows="10" onchange='this.value=unescape(escape(this.value).replace(/%0D%0A/g,"\\n"))'></textarea>

08-01-2002, 04:38 PM
Yeah sorry I do mean a textarea (i keep doing that!).

what i'm trying to do is make somthing which generates the javascript for a quiz so the user types in his questions and answers then he clicks a button a the Javascript for the quiz appears in the textarea. but when you tell the next area to have a "\n" in it makes a line break but I want the textarea to shoe the "\n" instead of making a line break.

Hope that makes it clearer

08-01-2002, 04:40 PM
thanks for the script John but i don't understand this bit: onchange='this.value=unescape(escape(this.value).replace(/%0D%0A/g,"\\n"))'>

08-01-2002, 04:47 PM
It was just an example to show you how it could work. Let me break it down:


when the value of the textarea changes, escape the value which will basically URL encode the text. Then replace all instances of %0D%0A, which is the line break, with \n. Then unescape everything so the URL encoded text goes back to normal.

08-01-2002, 04:55 PM
here is an exmple, load this up in your browser and have a look:

<script language="JavaScript">
var txt='hello'+' bye '+'\n hello';

<form name='end'>
<textarea cols="40" rows="10" name='end'>click go</textarea>
<input type="button" value='go' onClick='this.form.end.value=txt;'>
see the \n makes a line break but I don't want it to I want the textarea to say "hello bye \n hello"

08-01-2002, 04:59 PM
Try escaping the "n" with an additional backslash:


08-01-2002, 05:02 PM
Thank you very much that has sloved my problem THANK YOU

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum