Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2003
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    finding the value of the first line of a textarea

    with javascript,

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

    Code:
    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?

    thanks

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think this will work (untested)
    Code:
    var value=window.document.form_1.textarea_1.value.split(/\n/g);
    Try it out?

  • #3
    Regular Coder
    Join Date
    Dec 2003
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


    thanks

    big help

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    That's called regular expression 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);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •