Forum Moderators: open

Message Too Old, No Replies

javascript: loop through items

         

kristof_v

5:59 pm on Aug 30, 2006 (gmt 0)

10+ Year Member



hi,

i have 4 input fields:
txt1
txt2
txt3
txt4

now i have a for loop like:
for (var i=0; i<4; i++) {
txt+i.value = parseFloat(txt+i.value) * 2
}

i need to append the i value to txt so i don't to write 4 lines of code.
but i don't know how to do this in javascript?

grtz

Fotiman

6:06 pm on Aug 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



for (var i=0; i<4; i++) {
eval("txt"+i+".value = parseFloat(txt"+i+".value) * 2");
}

kristof_v

6:48 pm on Aug 30, 2006 (gmt 0)

10+ Year Member



thx a lot!