Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TEXTAREA SPLIT

Status
Not open for further replies.

breyt

IS-IT--Management
Dec 9, 2002
66
FR
HI
I have a textarea of rows= 15 column =60 max 720 caracters.
how i can split in 15 lines of 60 caraters
thanks
breyt
 
If I understand your question correctly, something like this...

Code:
var textArray = new Array();
for(var i=0; i<textAreaName.value.length; i+=60)
 textArray[textArray.length] = textAreaName.value.substring(i, i+60);

The split would not care, however, about cutting words in half. 'don't know your exact needs, but maybe this would get you started.

Does that help?

--Dave
 
thsi is my code and it dont work
function loads (sym)
{
var textArray = new Array ();
for(var i=0; i<sym.value.length; i+=60)
textArray[textArray.length] = sym.value.substring(i,i+60);
}
</script>
thanks breyt
 
How do you know it isn't working? What happens? Do you get an error message? If so, what's the message?

Let's see the HTML where loads(...) is called.

Also, remember that since textArray is declared within the function, it goes out of scope when you leave the function. Put the var textArray declaration outside the function so it becomes a global var and you will be able to access it elsewhere..

--Dave
 
HI
my code
___________________________
var sym=document.f0.SYMPTOME.value;
alert("sym"+sym);
var textArray = new Array();
for(var i=0; i<sym.value.length; i+=60)
textArray[textArray.length] = sym.value.substring(i, i+60);
alert("text="+textArray);
____________________________
error: value.length value null or not an object
thanks breyt
 
from what I see, sym already is the value of SYMPTOME so you need to replace
Code:
for(var i=0; i<sym.value.length; i+=60)
with
Code:
for(var i=0; i<sym.length; i+=60)
and
Code:
sym.value.substring(i, i+60);
with
Code:
sym.substring(i, i+60);
 
Hi
thanks for this answer. how i can display textArray to verify if it work
I must fill diiferents filed like
document.f0.SYM01.value with the content of row 1 (60 caracters)
document.f0.SYM02.value with the content of row 2 (60 caracters)
thanks
breyt
 
Try:

Code:
for(var i=0; i<sym.value.length; i+=60)                     
{
 textArray[textArray.length] = sym.substring(i, i+60); 
 alert(textArray[textArray.length - 1];
}

Notice that to load and then show the last entry in the textArray, you load it into the textArray.length position, but then, because you've just increased the length by 1, to view it, you must consider the index one less than textArray.length (ergo, the '- 1' in the alert).

--Dave
 
HI
Thanks its works !!
I want to force the array to 12 values how I cant do it . because when i enter only two line (2 * 60) all the other values contains 'undefined'
thanks
breyt
 
Post the code you've got right now.

Why do you want to force the array to be of size 12?

--Dave
 
Hi
because I udate a data base after with 12 field and I need blank field
Breyt
 
If you gather the text like in the above-code, you can just fill remaining indeces in the array with blanks:

Code:
function gatherText()
{ 
 var textArray = new Array();

 [b]//load the array[/b]
 for(var i=0; i<textAreaName.value.length; i+=60)                     
 {
  textArray[textArray.length] = textAreaName.value.substring(i, i+60); 
 }

 [b]//fill it up with blanks[/b]
 for(var j=textArray.length; j<12; j++)
 {
  textArray[textArray.length] = "";
 }

 [b]//this will show you the array contents[/b]
 for(var k=0; k<textArray.length; k++)
 {
  alert(k + ": " + textArray[k]);
 }
}

'hope that helps.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top