473,396 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem with code to calculate total values in textboxes that are added dynamically

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function calcvaluesArr(){
  3. var txts = document.getElementsByName('textfield23[]');
  4.         var aTotal=0;                      
  5.          for (var i = 0; i < txts.length; i++) 
  6.           {         
  7.             if (txts[i].value!="") 
  8.                { 
  9.                 aTotal=eval(aTotal)+eval(txts[i].value);
  10.               } 
  11.         } 
  12. document.form.textfield19.value=aTotal;
  13. }
  14. </script>
Sep 15 '10 #1
6 2456
Canabeez
126 100+
Here, look into this, believe this might help you:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function calculate(){
  3.         var textFields = document.getElementsByName('txt');
  4.         var total = 0;
  5.  
  6.         for(var i in textFields){
  7.             if(textFields[i].value){
  8.                 total += parseFloat(textFields[i].value);
  9.             }
  10.         }
  11.  
  12.         document.getElementById('total').value = total;
  13.     }
  14.  
  15.     window.onload = function(){ calculate(); };
  16. </script>
  17. <input type="text" name="txt" value="1" onkeyup="calculate()" />
  18. <input type="text" name="txt" value="2" onkeyup="calculate()" />
  19. <input type="text" name="txt" value="3" onkeyup="calculate()" />
  20. <input type="text" name="txt" value="4" onkeyup="calculate()" />
  21. <input type="text" name="txt" value="5" onkeyup="calculate()" />
  22.  
  23. <input type="text" name="total" id="total" value="0" readonly />
Good luck.
Sep 15 '10 #2
The issue now is:

1. Canabeez, your code does not run in IE8
2. I am not able to get the values inserted into mysql using php

Any ideas on these?

Thanks again
Sep 15 '10 #3
Canabeez
126 100+
Sorry, I'm a mac user, unable to check on IE8 :/ are you getting some JS errors?

Show some php/javascript/mysql code for further assistance.
Sep 15 '10 #4
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. foreach($textfield23 as $a => $b){
  4. $qins = "INSERT INTO myTable VALUES(NULL, $reqid, $selecta[$a], '$textfield23[$a]', '', '', NOW())";
  5. mysql_query($qins) or die(mysql_error());
  6. ";
  7.  
  8. }
  9.  
  10. ?>
  11.  
Sep 15 '10 #5
No JS errors are are showing
Sep 15 '10 #6
This is the JavaScript

Expand|Select|Wrap|Line Numbers
  1. function calculate(){
  2.         var textFields = document.getElementsByName('textfield23');
  3.         var total = 0;
  4.  
  5.         for(var i in textFields){
  6.             if(textFields[i].value){
  7.                 total += parseFloat(textFields[i].value);
  8.             }
  9.         }
  10.  
  11.         document.getElementById('textfield19').value = total;
  12.     }
  13.  
  14.     window.onload = function(){ calculate(); };
  15.  
Sep 15 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jigar Mehta | last post by:
Hye, This is Jigar mehta from India. I have made one application that adds dynamic menu items from the database. Each menu item has one ID and menu item's text is coming from the database. Now, I...
3
by: Forconi Boris via .NET 247 | last post by:
Hi, I'm working on a project in witch I have to list data(products that can be selected with a certain quantity) from anXML document, with key words entered by the user. A Table isdynamically created...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
1
by: nzrusty | last post by:
Im trying to work out the total values of a table, which i have read from a file x y 1.0 2.876 2.6 4.234 3.7 8.874 4.5 7.698 6.0 9.932 I want to work out the total values of x, i.e...
1
by: ram achar | last post by:
please send me C# code for inserting values into database sql server2005 *** Sent via Developersdex http://www.developersdex.com ***
2
by: 06mca30 | last post by:
How to calculate total no of hits for my home page?
4
by: mitdej | last post by:
Hi there, I have an several enum types that starts from a nunmber other than 0. For example: public enum InternalStatus { Pending = 1, Ported = 2, Suspended = 3 } I put this values in a int...
2
by: amolrwaghmare | last post by:
hi, is anybody know javascript code for calculatiing values from two textboxes n put it in another????
3
by: John Torres | last post by:
how do you calculate total time hours? I have sub total hours for each day and I've been trying to total all the hours. I'm getting odd numbers. Thanks. John
3
by: frenzy99 | last post by:
Can some one help me with this problem. I want to sort DataGridView based on the order in which values were added, not on the basis of any particular column, unlike the functionality provided by...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.