473,835 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to calculate the total for below code

1 New Member
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="javascript">
  4. var i=0,ta="T",qa="Q",ra="R",k=0.0,j=0.0;
  5.  
  6. function addRowToTable()
  7. {
  8.   var tbl = document.getElementById('ad');
  9.   var lastRow = tbl.rows.length - 6;
  10.   var iteration = lastRow ;
  11.   var row = tbl.insertRow(lastRow);
  12.  
  13.   var cellRight = row.insertCell(0);
  14.   var el = document.createElement('input');
  15.   el.type = 'text';
  16.   el.name = 'I' + iteration;
  17.   el.id = 'I' + iteration;
  18.   el.size = 20;
  19.  
  20.   var cellRight1 = row.insertCell(1);
  21.   var el1 = document.createElement('input');
  22.   el1.type = 'text';
  23.   el1.name = 'Q' + iteration;
  24.   el1.id = 'Q' + iteration;
  25.   el1.size = 14;
  26.   el1.onblur='add1.focus()';
  27.  
  28.   var cellRight2 = row.insertCell(2);
  29.   var el2 = document.createElement('input');
  30.   el2.type = 'text';
  31.   el2.name = 'R' + iteration;
  32.   el2.id = 'R' + iteration;
  33.   el2.size = 15;
  34.   el2.onblur='res()';
  35.  
  36.   var cellRight3 = row.insertCell(3);
  37.   var el3 = document.createElement('input');
  38.   el3.setAttribute("type","text");
  39.   el3.name = 'T' + iteration;
  40.   el3.id = 'T' + iteration;
  41.   el3.size = 15;
  42.  
  43.  el2.onkeypress=keyPressTes;
  44.  document.getElementById("ti").value=iteration;
  45.  
  46.  cellRight.appendChild(el);
  47.  cellRight1.appendChild(el1);
  48.  cellRight2.appendChild(el2);
  49.  cellRight3.appendChild(el3);
  50.  el.focus();
  51. }
  52.  
  53. function keyPressTes()
  54.     var key;
  55.    if(window.event) 
  56.    key = window.event.keyCode; 
  57.    if(key == 08 )
  58.    {
  59.        alert("1");
  60.        res();
  61.        alert("2");
  62.    }
  63. }
  64.  
  65. function removeRowFromTable()
  66. {
  67.   var tbl = document.getElementById('ad');
  68.   var lastRow = tbl.rows.length;
  69.   if (lastRow > 8) 
  70.   {
  71.   var tt = lastRow - 7;
  72.   ta="T";
  73.   ta=ta+tt;
  74.   tbl.deleteRow(lastRow - 7);
  75.   document.getElementById("ti").value=lastRow - 8;
  76.   ta="T";
  77.   i--;
  78.  }
  79. }
  80. </script>
  81. <script language='javascript'> 
  82. function res()
  83. {
  84. for (var a=0; a<=i; a=a+1) 
  85. {
  86.  ta="T"+a;
  87.  qa="Q"+a;
  88.  ra="R"+a;
  89.  var qt=document.getElementById(qa).value;
  90.  var rt=document.getElementById(ra).value;
  91.  var st=qt*rt;
  92.  document.getElementById(ta).value=st;
  93.  ta="T";
  94.  qa="Q";
  95.  ra="R";
  96.  i++;
  97.  qt=rt=st=0;
  98. }
  99. }
  100. </script>
  101. </head>
  102. <body>
  103. <form name="cnew">
  104. <table id="ad">
  105.   <tr>
  106.     <td width="123" align="left" height="1"><b>Item</b></td>
  107.     <td width="86" align="left" height="1"><b>QUANTITY</b></td>
  108.     <td width="86" align="left" height="1"><b>RATE</b></td>
  109.     <td width="86" align="left" height="1"><b>TOTAL</b></td>
  110.   </tr>
  111.   <tr>
  112.     <td width="123" align="left" height="5">
  113. <input type="text" name="I0" size="20" id="I0"></td>
  114.     <td width="86" align="left" height="5">
  115. <input type="text" name="Q0" size="14" id="Q0"></td>
  116.     <td width="86" align="left" height="5">
  117. <input type="text" name="R0" size="15" id="R0" onblur="res()"></td>
  118.     <td width="86" align="left" height="5">
  119. <input type="text" name="T0" size="14" id="T0"></td>
  120.   </tr>
  121. </table>
  122. <p align="center"><input type="button" id="add1" value="Add" onclick="addRowToTable()" tabindex="8" name="Add" />&nbsp;
  123. <input type="button" value="Remove" onclick="removeRowFromTable();" />&nbsp; <input type="submit" value="Submit" name="B2">
  124. </form>
  125. </body>
  126. </html>
  127.  
Jun 7 '07 #1
1 1472
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

Use parseInt to parse a string into an integer.

What problem are you having?
Jun 8 '07 #2

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

Similar topics

1
10000
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a number. That number will appear in a seperate box at the bottom. So basically whatever you choose has a corresponding number associated with it (except for the text input, which you enter whatever number) and those numbers are added and produced in...
53
5763
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
4
13787
by: dmisen | last post by:
I have data on air pollution coming from sources across the country, and control options for reducing pollution from each source. The example below shows data for: - 2 sources (plant_ID "001" and "008") - total tons of pollution emitted from each source (20 and 25 tons, respectively) - an ID code for the each control device that could be applied to reduce the emissions - the control efficiency for each control device (percent that it...
7
4332
by: Jurek | last post by:
I have 10+ experience in C/C++ - mostly automation and graphics. I have never written any business apps though. Recently I've been asked to write a simple report that would calculate sales commission. The report needs to be generated from within a C/C++ app. I don't want to mess it up so I thought maybe someone from this group could give me some advice or point to me to a place that'll provide some background on the issue. Here is a...
4
6378
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost (cost). Users can dynamically add rows to the table so I don't know how many rows might need to be calculated. I need to calculate the total (qty * cost) and put that number in a table cell (or read only input box). I also need to sum the...
6
5271
by: kodt | last post by:
I have a form with 4 text input fields. The last one is the total of the previous three fields and should automatically calculate this value when a user enters data into any of the first 3. Normally I would put an onkeyup="" event on the input elements and have that call the function. However, this form is automatically generated based upon information in an XML file. I can add some HTML and Javascript to the page via the XML file, but cannot...
2
1533
by: shah1711 | last post by:
Dear all, Can somebody help me, how to make access calculate result. I am helping my friends (he is a teacher). He want to get results for his students. e.g if the student get 80 % of total mark, he will got "A". if the student get 40 % of the total mark, he will got "D" if the student get below 40%, he will get "FAIL". shah
3
11809
by: gator6688 | last post by:
I have to write a program that asks for a cost-per-item, number of items purchased, and a discount rate. Then it should calculate the total cost, tax due, and amount due. I have to use the formulas: total cost = number of items * cost-per-item total cost (discounted) = total cost - (discount rate * total cost) tax due = total cost * TAXRATE amount due = total cost + tax due I am going to put what I have so far. Any suggestions would be...
6
1482
by: novercent | last post by:
hi!! hello sir Madam, Im currently a Computer Science Student year 3 my teacher give an assingment to create a program.. can you help me? ...my problem is how to calculate the time ...I'll used Combo box for start then another combo box for The end and textbox for the Total hour..what code Iwill use : here the format of my program cbo1.AddItem " 06:00 AM " and so on.. = starting time cbo9.AddItem " 06:00 AM " and so on.. = end time...
11
2520
by: Connie via AccessMonster.com | last post by:
Hi Access Building Friends, I am building a database for a manufacturer who needs to know the projected End_Date of each job. I know the Start_Date and the total days required to do the job. I need to calculate the End_Date after taking into account Weekends and Holidays.
0
10815
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
10526
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...
0
10237
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9348
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7770
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
6970
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
4435
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
3999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3094
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.