Getting an Array() from a textarea form

Discussion in 'Javascript' started by DP, Aug 19, 2007.

  1. DP

    DP Guest

    I've just spent my day today trying to learn javascript for the first
    time, so the answer to this may seem obvious to some - but it's got me
    stumped.

    I want to be able to copy a column from an Excel spreadsheet and paste
    it into a webpage form, and have an array that I can manipulate.
    Maybe I'm missing a much better way to do this, but I've been thinking
    I need to use a textarea form, and split() the result into the array.
    My problem is that I can't seem to split() based on the hard-returns
    in the inputed text.

    Below is a simple example.
    If I enter the following, I get the results that I want (because it's
    split() on the spaces):
    AbC dEf GhI

    But if I enter the data the way I want to be able to, as follows, I
    can't find a way to make it work:
    AbC
    dEf
    GhI

    Am I missing the obvious, or what??
    Thanks,

    DH



    *******************

    <html>
    <head>

    <script type='text/javascript'>
    function makeupper(elem){
    var mySplitResult = elem.value.split(" ");
    for(i=0; i<mySplitResult.length; i++){
    document.write(mySplitResult + "<br/>");
    document.write(mySplitResult.toUpperCase() + "<br/>");
    }
    }
    </script>

    </head>
    <body>

    <form>
    Enter Stuff:
    <textarea name="txt" wrap="PHYSICAL" id="partnum"></textarea>
    <input name="Button" type='button'
    onclick="makeupper(document.getElementById('partnum'))"
    value='Get-R-Done' />
    </form>

    </head>
    <body>
    DP, Aug 19, 2007
    #1
    1. Advertising

  2. DP

    Paul Lautman Guest

    DP wrote:
    > I've just spent my day today trying to learn javascript for the first
    > time, so the answer to this may seem obvious to some - but it's got me
    > stumped.
    >
    > I want to be able to copy a column from an Excel spreadsheet and paste
    > it into a webpage form, and have an array that I can manipulate.
    > Maybe I'm missing a much better way to do this, but I've been thinking
    > I need to use a textarea form, and split() the result into the array.
    > My problem is that I can't seem to split() based on the hard-returns
    > in the inputed text.
    >
    > Below is a simple example.
    > If I enter the following, I get the results that I want (because it's
    > split() on the spaces):
    > AbC dEf GhI
    >
    > But if I enter the data the way I want to be able to, as follows, I
    > can't find a way to make it work:
    > AbC
    > dEf
    > GhI
    >
    > Am I missing the obvious, or what??
    > Thanks,
    >
    > DH
    >
    >
    >
    > *******************
    >
    > <html>
    > <head>
    >
    > <script type='text/javascript'>
    > function makeupper(elem){
    > var mySplitResult = elem.value.split(" ");
    > for(i=0; i<mySplitResult.length; i++){
    > document.write(mySplitResult + "<br/>");
    > document.write(mySplitResult.toUpperCase() + "<br/>");
    > }
    > }
    > </script>
    >
    > </head>
    > <body>
    >
    > <form>
    > Enter Stuff:
    > <textarea name="txt" wrap="PHYSICAL" id="partnum"></textarea>
    > <input name="Button" type='button'
    > onclick="makeupper(document.getElementById('partnum'))"
    > value='Get-R-Done' />
    > </form>
    >
    > </head>
    > <body>


    Try splitting on "\n"
    Paul Lautman, Aug 19, 2007
    #2
    1. Advertising

  3. DP

    DP Guest

    On Aug 19, 10:04 am, "Paul Lautman" <>
    wrote:

    <SNIP>
    >
    > Try splitting on "\n"



    Perfect! Thank you, thank you, thank you!

    DP
    DP, Aug 19, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Augustus
    Replies:
    1
    Views:
    350
    Ken Schaefer
    Sep 10, 2003
  2. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    326
    Anthony Jones
    Feb 5, 2006
  3. dan glenn
    Replies:
    5
    Views:
    252
    Lasse Reichstein Nielsen
    Jan 9, 2004
  4. Mike Brophy
    Replies:
    2
    Views:
    172
    Mike Brophy
    Jul 25, 2006
  5. Replies:
    1
    Views:
    308
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page