Getting an Array() from a textarea form

D

DP

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>
 
P

Paul Lautman

DP said:
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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top