Looping problem

1. Senior Member
Join Date
Dec 1969
Posts
294

## Looping problem

Something is wrong in the function, but i do not know exactly what it is. So, pl Help me.<BR> <BR>&#060;html&#062;<BR>&#060;script language="javascript"&#062;<BR>function cal(f)<BR>{ <BR>p=0<BR>for (var i=1;i&#060;4;i++)<BR>{<BR>p=p+parseFloat(f.p & i & .value) <BR>}<BR>f.result.value=p <BR>} <BR>&#060;/script&#062; <BR><BR>&#060;body&#062;&#060;form&#062;<BR>&#060; table&#062;&#060;tr&#062;&#060;td align=right&#062;&#060;input type="text" name=p1 size=6&#062;&#060;/td&#062;<BR>&#060;td align=right&#062;&#060;input type="text" name=d1 size=10&#062;&#060;/td&#062;&#060;/tr&#062;<BR>&#060;tr&#062;&#060;td align=right&#062;&#060;input type="text" name=p2 size=6&#062;&#060;/td&#062;<BR>&#060;td align=right&#062;&#060;input type="text" name=d2 size=10&#062;&#060;/td&#062;&#060;/tr&#062;<BR>&#060;tr&#062;&#060;td align=right&#062;&#060;input type="text" name=p3 size=6&#062;&#060;/td&#062;<BR>&#060;td align=right&#062;&#060;input type="text" name=d3 size=10&#062;&#060;/td&#062;&#060;/tr&#062;&#060;/table&#062;<BR>&#060;p&#062;<BR>&#060;input type="text" name="result" size=6 onclick="cal(this.form)"&#062;<BR>&#060;/form&#062;<BR>&#060;/script&#062;<BR>&#060;/body&#062;<BR>&#060;/html&#062;

2. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: Looping problem

this line<BR><BR>&#062; p=p+parseFloat(f.p & i & .value) <BR><BR>is totally and utterly wrong.<BR><BR>try this<BR><BR>p=p+parseFloat(f.elements["p" + i].value) <BR><BR>you might like to do the www.webmonkey.com javascript tutorial, because you&#039;re not looking great here

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•