Click to See Complete Forum and Search --> : Outputting array to textbox


IxxI
12-17-2003, 02:50 PM
I have an array into which I have placed a string of text in such a way that there is 1 letter per array element and no spaces. I now (for reasons better known to myself) want to output that into a textbox, but can't find the code to do it so that each array element is displayed. I've tried using

document.formname.textboxname.value = arrayname[num]

but that doesn't seem to work. Also I'd want all values of num from 0 to however long my sentence is displayed one after the other in the textbox. Can anyone think of a way to do this?

IxxI

Jona
12-17-2003, 02:56 PM
Hey old friend!
Do you have this online or viewable or something? I can't quite see what you're doing... Maybe just an example code or something?

[J]ona

IxxI
12-17-2003, 03:07 PM
Right here goes. Completely ignoring the guidlines about posting copious amounts of code. This is it:


<HTML>
<HEAD>
<TITLE> type_Document_Title_here </TITLE>
<script>

function arrit()
{

keywords = new Object();
var skeyword=document.arrform.toarr.value.toLowerCase();
var check=0;
var pos=0;
var i=0;
var j=1;
var k;
var len;

len = skeyword.length;

while (pos < len)
{
if (skeyword !=" ")
{
if (skeyword.substring(i,j) != " ")
{
keywords[check]=skeyword.substring(i,j);
check++;
i++;
j++;
}
else
{
i++;
j++;
}
}
else
{
break;
}
pos++;
}

for (k=0; k<check; k++)
{
alert(""+keywords[k]+"");
}
}
</script>
<BODY>
<form name="arrform" onSubmit="arrit()">
Enter the text here:
<BR>
<input type="text" name="toarr" size="50">
<BR><BR>
<input type="submit" value="Submit!" onClick="arrit()">
&nbsp;&nbsp;
<input type="reset" value="Clear Everything">
</form>

</BODY>
</HTML>


If you type a sentence (e.g hello my name is jona) into the textbox and submit it it should first put into an array and then alert you each letter of that sentence separately. So your sentence is now broken down into letters in the array keywords[]. All I want is to output keywords[] between [0] and [however long my sentence without spaces is] into theoriginal textbox.
Thanks,
IxxI

Jona
12-17-2003, 03:45 PM
for(k=0; k<=keywords.length; k++)
{
document.forms[0].toarr.value+=k;
}


[J]ona

IxxI
12-17-2003, 05:31 PM
Thanks for the reply Jona. I tried that and I tried

for(k=0; k<=keywords.length; k++)
{
document.forms[0].toarr.value+=keywords[k];
}

but neither produced any output in the textbox at all. Have you any other suggestions?
IxxI

Jona
12-17-2003, 06:10 PM
Hmm, try using document.arrform.toarr.value=skeyword

[J]ona

IxxI
12-17-2003, 06:46 PM
The problem with that is that that returns your original sentence (with spaces) as opposed to the one in the array (without spaces).
NB The important thing isn't the spaces or lack thereof its the fact that I can play around with the order of the letters in the array too and I want to output that. With/without spaces is just an example of that.
IxxI

Jona
12-17-2003, 10:13 PM
Hmm... I guess I'm not following you...

[J]ona