josh wrote:
Quote:
Hi, if I have an array like this:
>
var a = new array(1,2,3);
>
then I make
>
txt.value = a.join("\n");
>
where txt is a textarea, in that textarea the string returned from join
is correctly formatted as
tre values separated by a line feed and so displayed ... but if I pass
the delimiter from a variable
then the texarea show also this delimiter...
>
var del = form.del.value; // here value entered is \n
txt.value = a.join(del);
>
in the textarea I'll have:
1\n2\n3
and not
1
2
3
Why?
>
P.S. If I pass a value like %0D and then make:
txt.value = unescape(a.join(del));
it works well!
Hi
Your problem is here:-
Quote:
var del = form.del.value; // here value entered is \n
txt.value = a.join(del);
in that you are confusing escaped characters in JavaScript "string
literals" in code, and text entered into a text area or input box.
If you use "\n" or '\n' in a string literal in JavaScript code, then
this is converted by the JavaScript parser into an 0A character.
If you type \n into a textarea or text box, your textarea or input box
does not recognise this as an escaped character, simply as "\" and "n"
literally. It is the equivalent of "\\n" in code.
Quote:
P.S. If I pass a value like %0D and then make:
txt.value = unescape(a.join(del));
it works well!
This case is no different, but for one exception, you have added
"unescape", which does the work of converting %0D into an 0D character.
In your first example you need to do the same, i.e. write some code
which looks for and can convert a "\n" into an 0A character.
Regards
Julian Turner