adding values in the textbox and put total in same
Anu Sri
Ranch Hand
Joined: Jul 29, 2002
Posts: 43
posted
0
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: 1865
posted
0
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
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
posted
0
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: 15357
6
posted
0
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;