Page 1 of 1

calculate sum & onclick function

Posted: Fri May 06, 2011 1:27 am
by ishakya
Hi all,
i need to calculate sum of values of all text boxes.But i'm using onclick function for those text boxes.
let me explain it to you further.
here is my code:

Code: Select all

<tr>
            <td width="100">Charges</td>
            <td><input name="txt_pr" type="text"  id="txt_pr" value="" size="10" maxlength="10" /></td>
             <td><input name="txt_lf" type="text"  id="txt_lf" value="" size="10" maxlength="20" /></td>
            
            <td><input name="txt_lf" type="text"  id="txt_lf" value="" size="10" maxlength="20" onClick="this.value=calcTot(document.getElementById('txt_pr').value,document.getElementById('txt_lf').value)" /></td>
          </tr>
Once user enter values to txt_pr & txt_lf, i have written a function to multiply them & place them in txt_lf text box.i use onclick function to call that javascript function.Function name is calcTOT
Function is pasted below:

Code: Select all

<script>
function calcTot(qty,unitp)
       {
var tot=0;
tot=parseFloat(qty)*parseFloat(unitp)*parseFloat(rate);
return tot;
       }
</script>


1st question:
Can i do that using onchange function?
if can, how it can be done?
2nd question:
How should i get sum of all text boxes that i used in my page?.i'm using 35 text boxes in my page.

Hope that everyone understood my problem.Can anyone help me to solve this matter?

Thanks in advance....

Re: calculate sum & onclick function

Posted: Fri May 06, 2011 10:42 am
by incubi
I just ran into this issues elsewhere have a look here.

http://www.codingforums.com/archive/ind ... 71910.html

Re: calculate sum & onclick function

Posted: Sun May 08, 2011 10:39 pm
by ishakya
thanks a lot my friend......
Hope it will help me to solve my problem.....