0

I have PHP page including Javascript,

my issue that I need to calculate textboxs in other textbox on same page , if count of textboxs is fixed its true working like

allval=allval+parseFloat(theForm5.totmountx1.value); 
allval=allval+parseFloat(theForm5.totmountx2.value); 
allval=allval+parseFloat(theForm5.totmountx3.value); 
allval=allval+parseFloat(theForm5.totmountx4.value); 

but my totmountx have variable number depends on user inputs , i tried to write , but its not working ,

enter code here

for (var i=1;i<=seq;i++)
{
var allval=allval+parseFloat(theForm5.totmountx+i.value);
}
Artyom Neustroev
  • 8,627
  • 5
  • 33
  • 57
wael
  • 3
  • 1

1 Answers1

1

Use

theForm5['totmountx'+ i].value

Also, it should be:

var allval = 0;
for (var i = 1; i <= seq; i++) {
    allval += parseFloat(theForm5['totmountx'+ i].value);
}

Otherwise you try to initialize the variable multiple times.

Jakub Kotrs
  • 5,823
  • 1
  • 14
  • 30