473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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 2471
Canabeez
126 New Member
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
amek000
5 New Member
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 New Member
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
amek000
5 New Member
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
amek000
5 New Member
No JS errors are are showing
Sep 15 '10 #6
amek000
5 New Member
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
1951
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 want to get the notification of the menu item click which is added dynamically. I want to put one common routine where I can distinguish between all menu item clicks. Menu Items can be two or hundred. So, how to make one handler that will be...
3
5293
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 with text, and in each row, there 's atextBox (with an incremental ID number) in witch the user canenter a number of products. When the user clicks on the "Submit"button, I must know witch row he has selected, AND WITCH NUMBERHE HAS ENTERED in the...
5
3736
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. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of controls to the webpage using the innerHTML method. It appears to work perfectly fine in the browser. The...
1
1468
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 sum of.
1
1800
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
4663
by: 06mca30 | last post by:
How to calculate total no of hits for my home page?
4
1985
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 column of a MSSQL table.
2
1501
by: amolrwaghmare | last post by:
hi, is anybody know javascript code for calculatiing values from two textboxes n put it in another????
3
2491
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
1339
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 DataGridView.Sort()
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.