calculate sum of all text boxes

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

calculate sum of all text boxes

Post by ishakya »

hi everyone,

i need to calculate the sum of all text boxes in to a single text box.
assume:
text box1=100, totaltextbox should be 100,
If i enter,
textbox1=250,textbox2=200.When i enter value to the textbox1,total should be 250.once i enter the second value to the textbox2,total should change to 450.it just like a onchange function.
this is not happening when i press submit button.it should happen automatically.When i leave the textbox1,total should display the value of text box1.then i enter textbox2,total should be the sum of textbox 1 & textbox 2.
Hope everyone got my point.
Please help me to solve this as soon as possible.
thanks in advance.......
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: calculate sum of all text boxes

Post by tr0gd0rr »

Basic idea: you'll want to use JavaScript's document.getElementsByTagName('input') and iterate through results. If input.type == 'text', add input.value to the total.
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

Re: calculate sum of all text boxes

Post by ishakya »

can you explain it more please?Because i have less knowledge in javascript


Thanks in advance
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: calculate sum of all text boxes

Post by tr0gd0rr »

Post Reply