Click to See Complete Forum and Search --> : How would you do this


lmf232s
09-23-2004, 05:25 PM
I have an array of txtboxes named txtWFG1 - txtWFG17
I have another array of txtboxes named txtOSO1 - txtOSO17

What i need to be able to do is when i click a button,
have the value of

txtWFG1 = txtOSO1

For all 17 text boxes.

I tried something like this.

var oForm = "document.form";
for (i = 0; i < 17; i++){
oForm.elements[txtWGF+i].value = oForm.elements[txtOSO + i].value;
alert(" i made it ") ;
)


I am having problem building the name of the text box for each.

I could just have 34 variables and set one = to another but i rather not.
I rather use a loop and do it on the fly.

How do i accomplish this guys.

Thanks.

HaganeNoKokoro
09-23-2004, 05:30 PM
You need to use quotes

oForm.elements["txtWGF"+i].value = oForm.elements["txtOSO" + i].value;

also, if they're 1-17, your loop should go from 1 to 17, not 0 to 16

Willy Duitt
09-23-2004, 05:32 PM
Try this:


var oForm = "document.form";
for (var i = 1; i <= 17; i++){
oForm.elements['txtWGF' + i].value = oForm.elements['txtOSO' + i].value;
alert(" i made it ") ;
)


.....Willy

Ooops.... SlowTyper that's me! :eek:

lmf232s
09-23-2004, 05:38 PM
thanks guys works like a charm. I would of gotten it i think but
the i = 0 was throughing an error that would of taken some time to catch. and i had the damn txtbox name spelled wrong, lol.

Its always better to have a couple of eyes looking at somehthing.

I have had this problem all week long of phat fingering keys and getting errors and not being able to tell.

Anyways thanks.

oh ya one of you used " and the other used ',
I tried both ways and both work.

Again thanks.

Willy Duitt
09-23-2004, 05:47 PM
It doesn't matter if the delimiter is single or double quotes...
It's all rather a matter of preference...

I prefer to use single quotes for all javascript so that I do not ever need to escape double quotes of any html quoted attributes which may be included in document.writes or innerHTML... However, I do use double quote delimiters for alerts to avoid escaping single quotes in such as string's....

.....Willy

lmf232s
09-23-2004, 07:09 PM
Thats a good point,
I was unaware that you could use either or(being farily new with javascript).