Click to See Complete Forum and Search --> : User a variable form field name


rovi
05-31-2005, 04:50 PM
Hi,
I have this javascript code that passes a value to a form field, but the form field name is variable and depends on the variable i.
if (i==2){
document.PAYamount_2.value=document.FINAL.SELSHIPPING.value;
}else if (i==3){
document.PAY.amount_3.value=document.FINAL.SELSHIPPING.value;
}else if (i==4){
document.PAY.amount_4.value=document.FINAL.SELSHIPPING.value;

How could I construct the form field such that I dont have to write the if else statements and just use variable (like:
document.PAY.amount_[i].value=document.FINAL.SELSHIPPING.value;)

Thanks!

Exuro
05-31-2005, 06:11 PM
Like this:
document.PAY["amount_"+i].value = document.FINAL.SELSHIPPING.value;