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);
}

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

For more information about types of notation, have a look at this: stackoverflow.com/questions/4968406

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.