473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

newlines in textarea on different platforms

Hello,

Recently I created a validation script for a form
that checks a textarea. The visitor is invited to
send a list of 25 words, with each word on a new
line.

Before I submit the list I run a test that checks
the length of each word. In order to do this I split
the content of the textarea to create an array of
words that I can loop through.

For the split I'm using the following code:

var entries = list.value.split("\n");

It works fine with me, but I'm wondering if this
will also work on Mac computers.

Or should I write something like:

if(navigator.appVersion.indexOf("Mac") != -1) {
var entries = list.value.split("\r");
} else {
var entries = list.value.split("\n");
}

Thanks,

Jos

(PS. I know that windows uses "\r\n" but that is
dealt with in the subsequent code).

Jul 23 '05 #1
4 1903
ASM
Jos van Uden wrote:
Hello,

Recently I created a validation script for a form
that checks a textarea. The visitor is invited to
send a list of 25 words, with each word on a new
line.

Before I submit the list I run a test that checks
the length of each word. In order to do this I split
the content of the textarea to create an array of
words that I can loop through.

For the split I'm using the following code:

var entries = list.value.split("\n");

It works fine with me, but I'm wondering if this
will also work on Mac computers.

yes '\n' works fine on (my) Mac

<form>
<textarea name="vue" cols=30 rows=10></textarea>
<a href="#"
onclick="alert(document.forms[0].vue.value.split('\n'));">voir</a>
</form>

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #2
ASM wrote:
Jos van Uden wrote:
[...]
yes '\n' works fine on (my) Mac

<form>
<textarea name="vue" cols=30 rows=10></textarea>
<a href="#"
onclick="alert(document.forms[0].vue.value.split('\n'));">voir</a>
</form>


Here's an alternative, provided a 'word' is delimited by any amount of
white space (including returns, newlines, tabs, whatever). I can't
think of any words that have whitespace in them, but I don't know many
languages!

<form action="">
<textarea name="ta"></textarea>
<input type="button" value="click me" onclick="
var x = this.form.ta.value.split(/\s+/);
alert(x.join('\n'));
">

--
Fred
Jul 23 '05 #3
Jos van Uden wrote:
Hello,

Recently I created a validation script for a form
that checks a textarea. The visitor is invited to
send a list of 25 words, with each word on a new
line.

Before I submit the list I run a test that checks
the length of each word. In order to do this I split
the content of the textarea to create an array of
words that I can loop through.

For the split I'm using the following code:

var entries = list.value.split("\n");
var entries = list.value.split(/[\r\n]/);

Mick


It works fine with me, but I'm wondering if this
will also work on Mac computers.

Or should I write something like:

if(navigator.appVersion.indexOf("Mac") != -1) {
var entries = list.value.split("\r");
} else {
var entries = list.value.split("\n");
}

Thanks,

Jos

(PS. I know that windows uses "\r\n" but that is
dealt with in the subsequent code).

Jul 23 '05 #4
VK
> For the split I'm using the following code:
var entries = list.value.split("\n");
It works fine with me, but I'm wondering if this
will also work on Mac computers.


It works everywhere *within JavaScript*. Its "\n" sequence became kind
of getSystemDelimiter() from Java. So if you do:
myTextArea.value = string1 + "\n" +string2;
everyone will be happy:
Mac users will get "\r", Linux users will get "\n", Win users will get
"\r\n";

But if your are dealing with some text generated outside of JavaScript,
then of course "\r\n" or "\r" or "\n" are very different. Mick White
gave you an universal split().

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christopher Finke | last post by:
I have a site wherein the clients can update the individual pages by editing the text of that page in a <textarea>. Then, when the page is displayed, all of the newlines (\n) are converted to HTML...
4
by: Chris Sharman | last post by:
I haven't specified fonts, leaving the user to have their chosen font. However, different tags render in different default fonts: text, input, & textarea all different from one another. I guess...
1
by: bbcrock | last post by:
Can Javascript control sections of a textarea using divs, etc? We have templates that unfortunately contain some free-text sections where our clients cannot come to aggreement. I would LOVE to do...
8
by: Mark D. Smith | last post by:
Hi I have googled but not found a solution to wordwrap in a textarea using firefox/netscape. is there a style sheet solution or am i stuck with not being able to force wrapping in a textarea...
6
by: Phil Endecott | last post by:
Dear Experts, I have some Javascript code that reads and sometimes sets the content of a textarea. I want this to be reasonably browser and platform independent. My question is, what...
1
by: HopfZ | last post by:
Not a question. I tested how two kinds of newlines (\n and \r\n) interact with three browsers: Fx (Firefox 2), Op (Opera 9), Ie (IE 7) (all three on Windows XP). Result: The string...
14
by: Rob | last post by:
I am trying to perform client-side input validation for a textarea to determine that the number of characters doesn't exceed a certain length. Currently, I am just using str.length, but if the...
4
by: lihao0129 | last post by:
Hi, folks: I recently went through a strange problem with my Javascript code, say: I have a string variable which are from a 'textarea' element and I want to remove the trailing newlines inside...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.