473,672 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculate on the fly

3 New Member
Hey guys im doing a POS for my body's store and im really bitting my nails on the form total calculations.

this is a test script
but it only calculates the grand total not the form part

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript">
  2.  
  3. ///////////this is for filed total
  4.         function calc(A,B,SUM) { 
  5.   var one = Number(A); 
  6.   if (isNaN(one)) { alert('Invalid entry: '+A); one=0; } 
  7.   var two = Number(document.getElementById(B).value);  
  8.   if (isNaN(two)) { alert('Invalid entry: '+B); two=0; } 
  9.   document.getElementById(SUM).value = one + two; 
  10. }
  11.  
  12.  
  13. /////////////this is for grand total 
  14. function calcTotal(txtBox, totBox)
  15. {
  16.     var totVal;
  17.     try
  18.     { 
  19.     totVal = document.getElementById(totBox).value;
  20.     if(totVal!= null && totVal!='')
  21.      {
  22.        document.getElementById(totBox).value= eval(parseInt(document.getElementById(totBox).value) + parseInt(txtBox.value));   
  23.      }
  24.      else
  25.      {
  26.         document.getElementById(totBox).value= txtBox.value;           
  27.      }
  28.     }
  29.     catch(e)
  30.     {}
  31. }
they both work individual but when i add one it stops the filed calculator

Expand|Select|Wrap|Line Numbers
  1. <table> 
  2. <tr> 
  3. <td width="337"><input name="sum1" id="op1" value="" onChange="calc(this.value,'op2','result')" />  <input name="sum2" value="" id="op2" onChange="calc(this.value,'op1','result')" /></td> 
  4. <td width="176"><input type="text" id="result" onBlur="calcTotal(this, 'tot')" /></td> 
  5. </tr> 
  6. <tr>     
  7. <td><input name="op" id="op3" value="" onchange="calc(this.value,'op4','result2')" /><input name="op" value="" id="op4" onchange="calc(this.value,'op3','result2')" /></td> 
  8. <td><input type="text" id="result2" onBlur="calcTotal(this, 'tot')" /></td> 
  9. </tr> 
  10. <tr>     
  11. <td> <input name="op" id="op5" value="" onchange="calc(this.value,'op5','result3')" /><input name="op" value="" id="op6" onchange="calc(this.value,'op6','result3')" /></td> 
  12. <td><input type="text" id="result3" onBlur="calcTotal(this, 'tot')" /></td>        
  13. </tr> 
  14. <tr>     
  15. <td>Total</td> 
  16. <td><input type="text" id="tot" /></td> 
  17. </tr>    
  18. </table> 
Aug 11 '14 #1
2 1498
techker
3 New Member
ok so i got this to work

but i need to calculate taxes.do i need to creat a var ta1 and tax 2?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function hello(){ 
  3. var xx=eval(form1.sum1.value); 
  4. var yy=eval(form1.sum2.value); 
  5. form1.result.value=xx+yy 
  6. </script>    
  7.  
  8.  
  9.         <script type="text/javascript">
  10.  
  11. function calcTotal(txtBox, totBox)
  12. {
  13.     var totVal;
  14.     try
  15.     { 
  16.     totVal = document.getElementById(totBox).value;
  17.     if(totVal!= null && totVal!='')
  18.      {
  19.        document.getElementById(totBox).value= eval(parseInt(document.getElementById(totBox).value) + parseInt(txtBox.value));   
  20.      }
  21.      else
  22.      {
  23.         document.getElementById(totBox).value= txtBox.value;           
  24.      }
  25.     }
  26.     catch(e)
  27.     {}
  28. }
  29. </script>
Aug 11 '14 #2
techker
3 New Member
got the tax..but as soon as i add the code for auto suggest tax stops and auto works??

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript">
  2.     $(document).ready(function(){
  3.         $('#calx').calx({
  4.         autocalculate: false
  5.         });
  6.  
  7.         $('#calculate').click(function(){
  8.         $('#calx').calx('update');
  9.         });
  10.     });
  11.     </script>
  12.  
  13.  
  14.  
  15.  
  16.     <style>
  17.     input[type="text"]{
  18.         width:100%;
  19.     }
  20.     td{
  21.         padding:5px 10px;
  22.     }
  23.     </style>
  24. </head>
  25. <body>
  26.     <form id="calx">
  27.     <table>
  28.         <thead>
  29.         <tr>
  30.             <td width="268" style="width:250px">Item Name</td>
  31.             <td width="162" style="width:80px">Price</td>
  32.             <td width="162" style="width:30px">Qty</td>
  33.  
  34.             <td width="168" style="width:150px">Sub Total</td>
  35.         </tr>
  36.         </thead>
  37.         <tbody>
  38.         <tr>
  39.             <td><input id="item1" type="text" name="item[]" value=""/></td>
  40.             <td><input id="price1" type="text" name="price[]" value="" data-format="$ 0,0[.]00" /></td>
  41.             <td><input id="qty1" type="text" name="qty[]" value="" data-format="0" /></td>
  42.  
  43.             <td><input id="subtotal1" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price1*$qty1)" /></td>
  44.         </tr>
  45.         <tr>
  46.             <td><input id="item2" type="text" name="item[]" value="" /></td>
  47.             <td><input id="price2" type="text" name="price[]" value="" data-format="$ 0,0[.]00" /></td>
  48.             <td><input id="qty2" type="text" name="qty[]" value="" data-format="0" /></td>
  49.  
  50.             <td><input id="subtotal2" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price2*$qty2)" /></td>
  51.         </tr>
  52.         <tr>
  53.             <td><input id="item3" type="text" name="item[]" value="" /></td>
  54.             <td><input id="price3" type="text" name="price[]" value="" data-format="$ 0,0[.]00" /></td>
  55.             <td><input id="qty3" type="text" name="qty[]" value="" data-format="0" /></td>
  56.  
  57.             <td><input id="subtotal3" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price3*$qty3)" /></td>
  58.         </tr>
  59.         <tr>
  60.             <td><input id="item4" type="text" name="item[]" value="" /></td>
  61.             <td><input id="price4" type="text" name="price[]" value="" data-format="$ 0,0[.]00" /></td>
  62.             <td><input id="qty4" type="text" name="qty[]" value="" data-format="0" /></td>
  63.  
  64.             <td><input id="subtotal4" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price4*$qty4)" /></td>
  65.         </tr>
  66.         <tr>
  67.             <td><input id="item5" type="text" name="item[]" value="" /></td>
  68.             <td><input id="price5" type="text" name="price[]" value="" data-format="$ 0,0[.]00" /></td>
  69.             <td><input id="qty5" type="text" name="qty[]" value="" data-format="0" /></td>
  70.  
  71.             <td><input id="subtotal5" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price5*$qty5)" /></td>
  72.         </tr>
  73.  
  74.         <tr>
  75.             <td height="39">&nbsp;</td>
  76.             <td>Total Price : </td>
  77.             <td colspan="2"><input id="total" type="text" name="total" value="" data-format="$ 0,0[.]00" data-formula="($subtotal1+$subtotal2+$subtotal3+$subtotal4+$subtotal5)" /></td>
  78.  
  79.         </tr>
  80.         <tr>
  81.           <td height="29">&nbsp;</td>
  82.           <td>Tax1:</td>
  83.           <td colspan="2"><input id="totaltax1" type="text" name="totaltax" value="" data-format="$ 0,0[.]00" data-formula="($total+($total*5.00/100))" /></td>
  84.  
  85.           </tr>
  86.         <tr>
  87.           <td height="29">&nbsp;</td>
  88.           <td>Tax2:</td>
  89.           <td colspan="2"><input id="totaltax2" type="text" name="totaltax" value="" data-format="$ 0,0[.]00" data-formula="($total+($total*9.975/100))" /></td>
  90.  
  91.           </tr>
  92.         <tr>
  93.           <td height="42"><input id="calculate" type="button" value="calculate" /></td>
  94.           <td>Tax in :</td>
  95.           <td colspan="2"><input id="totaltax" type="text" name="totaltax" value="" data-format="$ 0,0[.]00" data-formula="($total+($total*5.00/100+$total*9.975/100))" /></td>
  96.  
  97.           </tr>
  98.         </tbody>
  99.     </table>
  100.     </form>
Aug 12 '14 #3

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

Similar topics

2
4009
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum default is 4 letters). This is the Fed. Everything is a TLA (three-letter acronym). Therefore, since I'm building a PORTABLE web application, changing MySQL's default settings for fulltext index querying is completely undoable and unrealistic, so...
1
9983
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...
4
9334
by: Jan Szymczuk | last post by:
I'm creating an MS Access 2000 database where I have a number of people entered using simple basic fields, Surname: SMITH Forenames: John DoB: 09/09/1958 Age: (this needs to be automated to show years e.g. 46) I am trying to get the age to be automatically shown after a persons DoB (date of birth) is entered into the DoB field. I have tried using this formula in the Control Source of the Age field...
3
5959
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now calculate in the query the amount of weeks and days within the 17 days to show 2 weeks 3 days. I can create the function within excel, (A1 as cell with the days within it) as: =INT(A1/7) & " Weeks, " & MOD(A1,7) & " days" but cant seem to...
0
4635
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars (double) Sales Units (double) Promo (Text) -- is null or "X" AvgWklyDollars (double) AvgWklyUnits (double) I have a vba module which I thought would work, but it doesn't. I think the problem is an embedded SQL Totals Top 8 query, which doesn't...
6
4095
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the median of a recordset. The field must be a number value. Dim MedianTemp As Double Dim RstOrig As Recordset Set RstOrig = CurrentDb.OpenRecordset(RstName, dbOpenDynaset)
1
5110
by: mzovko20 | last post by:
Hello ! I´m having problem with this. I already created index.html document which allows user to input his/her date of birth. It looks like this : <html> <body> <center> <h3>How old are you ??</h3> <table border="0" width="25%"> <form action="calculate.php" method="get"> <td bgcolor="#FFCC00 ">Your name</td> <td><input type="text" name="name" maxlength="20" value="name"></td>
5
5907
by: Big P | last post by:
Hello, I would like to calculate cells in DataGridView ( VB Express) My datagridview1 looks something like this. --------------------------------------… Row# col1 col2 col3 Col 4 --------------------------------------… Row1 25 13 2 Row2 26 24 4
0
8419
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
8945
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
8847
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
8697
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
7476
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...
0
5720
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();...
0
4242
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2840
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

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.