View Full Version : finding the value of the first line of a textarea

03-17-2004, 10:50 PM
with javascript,

i know that you can find the value of a textarea by going like:

var value=window.document.form_1.textarea_1.value;

but i need an array to hold the values of all the different lines written.

is this possible?
if so, how?


03-17-2004, 10:54 PM
I think this will work (untested)

var value=window.document.form_1.textarea_1.value.split(/\n/g);

Try it out?

03-17-2004, 11:04 PM
well it worked!

ill be darned, but can you explain why? i know what \n does but i dont know what /g is and stuff.


big help

03-18-2004, 04:36 AM
That's called regular expression (http://www.regular-expressions.info/javascript.html) and the "g" enables global matching. But actually, the split() function expects a delimiter string, not a regexp object. And in IE, newline is composed of '\r\n' not '\n'.

var newline = (document.all) ? '\r\n':'\n';
var arrValue=window.document.form_1.textarea_1.value.split(newline);