File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding values in the textbox and put total in same

 
Anu Sri
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I need to add all text boxes values and put total in one text box value which is place in same page. Means:
textbox1= value user entered
textbox2= value user entered
textbox3= textbox1+textbox2 (values userentered)
Please tell me as soon as you can.
Thank you,
Anupama
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Anu
so when exactly you want to have that sum and put in the result text box? you use appropriate event to do this.
as far as javascript code for this might be concerned you can have a sort of following function that returns the addition of all the textfields you want to add,
var fieldsarray = new Array(document.myform.field1, document.myform.field2, document.myform.field3);
function storesumto(destination) {
var temp=0;
for(var i=0; i< fieldsarray.length; i++) {
temp += parseInt(fieldsarray[i].value,10);
}
destination.value = temp;
}
where destination might be document.myform.field4 which you pass to the function from where you are calling it.
hope this helps.
regards
maulin
 
Dan Drillich
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a straightforward code that does it -

Cheers,
Dan
 
Anu Sri
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maulin & Dan
I tried both ways. But I did not suceed. I dont know why? Actually I want onchange event like that. When user entering values into the text1 and text2, automaticaly adding values come on to the text3 without cliking any thing.
I dont know I am not succeed in that.I guess I did some thing wrong on it.
Please help me.
Thank you
Anupama
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at this code and see if it helps
<form name="A">
<input type="text" name="T1" size="3" onchange="CalcIt()">
<b>+</b>
<input type="text" name="T2" size="3" onchange="CalcIt()">
<b>=</b>
<input type="text" name="T3" size="3" onchange="CalcIt()">
</form>
<script>
function CalcIt(){
V1=document.A.T1.value*1;
V2=document.A.T2.value*1;
if(V1=="")V1=0;
if(V2=="")V2=0;
document.A.T3.value=V1+V2;

}
</script>
Eric
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic