• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Script Addition in for loop

 
Rashmi Trivedi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello frineds
I have one strage issue while i am doig the addition in java script inside foor loop.

Let me explain:
I have fetching records from database depending on the requst(query) submitted by users. Thy dynamic JSP page with the query results is display to the users.

i do have the row count so that i know how many rows have been retrieved from database.

I user this variable in javascript inside for loop to get the value of particular field in speific row.

var temp = document.warehouse.icount.value;
for (var i=1; i <= temp; i++) {
var amount = document.warehouse.elements["amount"+i].value;

} // end for
What i would like to do is add all the amounts and display it on the TotalAmount text box. I tried to do this but i am getting very funny results. Amout do not seem to be adding correctly and i cannot assign to Total Amount Coloumn.

Please help me out if you can guys...much appreciated..

let me know if you have any questions or need more clarification.

thank you in advance.

regards,
Rashmi Trivedi
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about you have a variable and you add each alue to it? In your code you are just storing the values into a variable and you kep writing over it.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic