calculate sum of all text boxes

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 of all text boxes

Post by ishakya »

hi,
i need to calculate the sum of all text boxes in to a single text box.
assume:
text box1=100, totaltextbox should be 100,
If i enter,
textbox1=250,textbox2=200.When i enter value to the textbox1,total should be 250.once i enter the second value to the textbox2,total should change to 450
.it just like a onchange function.
Hope everyone got my point.
Please help me to solve this as soon as possible.
thanks in advance.......
zyntrax
Forum Commoner
Posts: 32
Joined: Wed Apr 13, 2011 2:23 am
Location: Sweden

Re: calculate sum of all text boxes

Post by zyntrax »

If you mean dynamically, then i guess you have to use Java.
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

Re: calculate sum of all text boxes

Post by ishakya »

no this is not happening dynamically.Totally i got 30 text boxes.i need to calculate sum of that 30 text boxes.But sometimes user might enter all the text boxes or few of them. do you have any idea to do that?
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: calculate sum of all text boxes

Post by oscardog »

Wrong section. Try posting it in the JavaScript section.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: calculate sum of all text boxes

Post by AbraCadaver »

Using PHP and calculating on submit, you would name your text boxes like so: name="textbox[]". Then on the resulting page you can sum them all:

Code: Select all

$total = array_sum($_POST['textbox']);
Dunno if that's what you're going for.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply