473,396 Members | 1,779 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.

How to calculate the total for below code

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 1447
acoder
16,027 Expert Mod 8TB
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
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...
53
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...
4
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...
7
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...
4
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...
6
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. ...
2
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...
3
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...
6
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...
11
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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.