calculate sum & onclick function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

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

calculate sum & onclick function

Post 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....
incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: calculate sum & onclick function

Post by incubi »

I just ran into this issues elsewhere have a look here.

http://www.codingforums.com/archive/ind ... 71910.html
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

Re: calculate sum & onclick function

Post by ishakya »

thanks a lot my friend......
Hope it will help me to solve my problem.....
Post Reply