Home
TeamSite
how do i add new line charecter ?
madmax
i am tring a pretty printing in my textbox . 1st as u can see i have 2 array which r code[] and name[] . i want to print their value in a textbox in a dct . each line in the textarea will have---> code1----------name1 \n
code2----------name2 \n and so on.
but my newline in not happening? need the right javascript syntex for newline.
for (m = 0 ; m < calloutForm.elements.length ; m++ )
{
if (calloutForm.elements.name == '$element_name')
{
var ttText = " ";
for (n = 0; n <(code.length);n++ )
{
var tText = code + "-----" + name + "\n";
calloutForm.elements.value = tText;
var ttText = ttText + (calloutForm.elements.value);
}
calloutForm.elements.value = ttText;
calloutElementFound = true;
break;
}
}
Find more posts tagged with
Comments
Michael
You have the correct character - \n - for a new line.
The problem is most likely in your logic/coding. Defining ttText both inside and outside your for loop looks a bit unusual...
Here is a bit of rough html to show the new line character working...
<html>
<head>
</head>
<body>
<form name="form01">
<textarea name="ta01">
</textarea>
</form>
</body>
<script>
var myString = "JavaScript " + "\n" + " is EASY and fun. \n Try it today!" + "\n";
myString = myString + myString;
document.write(myString);
document.form01.ta01.value = myString;
alert(myString);
</script>
</html>
Hope that helps.
Cheers,
Michael
Migrateduser
I completely agree with Michael -- you
don't
need 2 vars in front of ttText as you do, but depending on how and where you're outputting your Javascript, you may need to place multiple escape characters in front of the n to get a newline. Reason being, if your JS is within a IWPerl block, for instance, Perl will strip away one of the backslashes. Thus, "\n" in JS becomes plain old "n". So, if you see lots of extraneous "n"'s sitting around, you might want to play with that.
Dave
Current Environment(s):
(1) TS 6.1 SP2 on W2K3
(2) TS 6.1 SP2 on W2K