aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes adding values in the textbox and put total in same Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "adding values in the textbox and put total in same" Watch "adding values in the textbox and put total in same" New topic
Author

adding values in the textbox and put total in same

Anu Sri
Ranch Hand

Joined: Jul 29, 2002
Posts: 43
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

Joined: Nov 04, 2001
Posts: 1871
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

Joined: Jul 09, 2001
Posts: 1180
Here is a straightforward code that does it -

Cheers,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Anu Sri
Ranch Hand

Joined: Jul 29, 2002
Posts: 43
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
subject: adding values in the textbox and put total in same