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!).
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:
var txt='hello'+' bye '+'\n hello';
<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
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.