Click to See Complete Forum and Search --> : How to assign variables to the texts in textbox or textarea?
Vincent001
04-11-2003, 08:17 PM
I want to "cut and paste" a paragraph or sentence into a textarea.
Then, when I press "submit" button. The text words will assign to differnt variables.
e.g. The sentence is "Hello!, I am Vincent."
Then, variable a[1]="Hello", a[2]="I", a[3]="am" and a[4]="Vincent" etc.
Thank you for help.
Regards,
Vincent.
Okay, something like
<script>
function s(){
var box = document.formName.textareaName.value;
var boxinf = box.split(" ").join(" ");
var arys = new Array();
for(i=0;i<boxinf.length;i++){
arys[i] = box.split(" ").join(" ");
}
</script>
I dunno... I'll work on it... :)
Actually, it will probably require use of substr or substring. I'll work on it... And show you what I got (Note: the above code I posted was not tested.).
Vincent001
04-11-2003, 08:33 PM
Hi, Jona
Thanks for your help. I look forward to seeing your reply.
Thank you very much.
Regards,
Vincent
Yah.. I'm working on it. I think I almost have it done. :)
Hey, unfortunately I have to go... So I'll work on your script and get back to you as soon as possible. Please don't count on it being tomorrow or Sunday. I'm really sorry, but I have to go... Adios
This may help you a little: http://www.geocities.com/god_loves_07/splitX.html
Vincent001
04-11-2003, 11:11 PM
Originally posted by Jona
This may help you a little: http://www.geocities.com/god_loves_07/splitX.html
No, this is not what i want.
No, but you can use that to split with a space instead of "" and a space instead of "" and then get the middle of it. Then set each of those to an array.
Nedals
04-12-2003, 12:45 AM
Jona was close...
var str = "Hello!, I am Vincent."
var ary = str.split(" ");
alert(ary[0]+ary[1]+ary[2]+ary[3]);
Hmm... Didn't know JavaScript automatically converted it to an array when it was split(). Thanks, Nedals. ;)
Nedals
04-12-2003, 01:59 PM
Another little trick that can sometimes be useful is when you want to manipulate characters in a string.
ary = str.split("");
This will put each individual char into an array. Then you can put it back together with...
str = ary.join("");
Vincent001
04-13-2003, 07:17 PM
Thanks Jona and Nedals.