By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,110 Members | 1,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,110 IT Pros & Developers. It's quick & easy.

how to fix the error?? thanks

P: 17
I have two similar function that need to be combined. Individually they both work however combined one over rides the other.
The code is attached below and an attachment is included for data information.

I have attached a screen shot of data
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Sample Tax Form</title>
  6. <style type="text/css">
  7. <!--
  8. body {
  9.     font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  10.     font-size: 12px;
  11.     font-style: normal;
  12.     font-weight: normal;
  13.     color: #000;
  14.     background-color: #70B8B8;
  15. }
  16. .th {
  17.     font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  18.     font-size: 14px;
  19.     font-style: normal;
  20.     font-weight: bold;
  21.     color: #FFF;
  22.     background-color: #066;
  23.     border-top-style: none;
  24.     border-right-style: none;
  25.     border-bottom-style: solid;
  26.     border-bottom-width: 1px;()
  27.     border-left-style: none;
  28. }
  29. .fill {
  30.     background-color: #C1E1E1;
  31.     border-top-style: none;
  32.     border-right-style: none;
  33.     border-bottom-style: solid;
  34.     border-left-style: none;
  35.     border-bottom-color: #000;
  36.     border-bottom-width: 1px;
  37. }
  38. .fill2 {
  39.     background-color: #C1E1E1;
  40.     border-top-style: none;
  41.     border-right-style: none;
  42.     border-bottom-style: none;
  43.     border-left-style: none;
  44.     border-bottom-color: #000;
  45.     border-bottom-width: 1px;
  46.     text-align: left;
  47. }
  48. table {
  49.     margin-left: auto;
  50.     margin-right: auto;
  51.     border-bottom-color:#FFF;
  52.     border-left-color:#FFF;
  53.     border-right-color:#FFF;
  54.     border-top-color:#FFF;
  55. }
  56. .line {
  57.     background-color:#70B8B8;
  58.     border-bottom: 0px solid #FFF;
  59. }
  60. -->
  61. </style>
  62. <script language="javascript">
  63. function currency(e)
  64.             {
  65.                 var temp = parseFloat(e.value.replace(/,/g,""));
  66.                 if(isNaN(temp))
  67.                     temp = 0;
  68.                 //if(e.id == "taxable_income" ||  e.id == "subtotal")
  69.                     //temp = (temp > 0 ? -temp : temp);
  70.                 //    e.style.color = "red";
  71.                     //e.style.color = "black";
  72.                 e.value = addcommas(temp.toFixed(2));
  73.             }
  74.  
  75. function addcommas(amount)
  76.             {
  77.                 var delimiter = ","; // replace comma if desired
  78.                 var a = amount.split('.',2)
  79.                 var d = a[1];
  80.                 var i = parseInt(a[0]);
  81.                 if(isNaN(i)) { return ''; }
  82.                 var minus = '';
  83.                 if(i < 0) { minus = '-'; }
  84.                 i = Math.abs(i);
  85.                 var n = new String(i);
  86.                 var a = [];
  87.                 while(n.length > 3)
  88.                 {
  89.                     var nn = n.substr(n.length-3);
  90.                     a.unshift(nn);
  91.                     n = n.substr(0,n.length-3);
  92.                 }
  93.                 if(n.length > 0) { a.unshift(n); }
  94.                 n = a.join(delimiter);
  95.                 if(d.length < 1) { amount = n; }
  96.                 else { amount = n + '.' + d; }
  97.                 amount = minus + amount;
  98.                 return amount;
  99.             }
  100.  
  101.  
  102.  
  103. function calc3(){
  104.                 var c1 = parseFloat(document.getElementById("subtotal").value.replace(/,/g,""));
  105.                 var c2 = parseFloat(document.getElementById("fed_withhold").value.replace(/,/g,""));
  106.                 var c3 = parseFloat(document.getElementById("state_withhold").value.replace(/,/g,""));
  107.  
  108.                 // Check for NaN's, and make sure debits are negative
  109.                 c1 = (isNaN(c1) ? 0 : c1);
  110.                 c2 = (isNaN(c2) ? 0 : (c2 > 0 ? -c2 : c2));
  111.                 c3 = (isNaN(c3) ? 0 : (c3 > 0 ? -c3 : c3));
  112.  
  113.                 // Make sure we are dealing with values rounded to the nearest cent before calculating, 
  114.                 c1 = parseFloat(c1.toFixed(2));
  115.                 c2 = parseFloat(c2.toFixed(2));
  116.                 c3 = parseFloat(c3.toFixed(2));
  117.  
  118.                 var temp = c1 + c2 + c3; 
  119.                 var cb = document.getElementById("total");
  120.                 cb.value = temp;
  121.                 currency(cb); 
  122.  
  123.             }                
  124. //---------------------------------------------------------------------------------------------------------------------------------------------------    
  125.     function calc4(){
  126.                 var d1 = parseFloat(document.getElementById("base_cash_value").value.replace(/,/g,""));
  127.                 var d2 = parseFloat(document.getElementById("cost_basis").value.replace(/,/g,""));
  128.  
  129.                 // Check for NaN's, and make sure debits are negative
  130.                 d1 = (isNaN(d1) ? 0 : d1);
  131.                 d2 = (isNaN(d2) ? 0 : d2);
  132.  
  133.                 // Make sure we are dealing with values rounded to the nearest cent before calculating, 
  134.                 d1 = parseFloat(d1.toFixed(2));
  135.                 d2 = parseFloat(d2.toFixed(2));
  136.  
  137.                 var temp = d1 - d2; 
  138.                 var cb = document.getElementById("taxable_income");
  139.  
  140.                 cb.value = temp;
  141.                 currency(cb); 
  142.  
  143.             }
  144. //--------------------------------------------------------------------------------------------------------------------------------------------------            
  145.     function calc5(){
  146.                 var c1 = parseFloat(document.getElementById("taxable_income").value.replace(/,/g,""));
  147.                 var c2 = parseFloat(document.getElementById("fed_withhold").value.replace(/,/g,""));
  148.                 var c3 = parseFloat(document.getElementById("state_withhold").value.replace(/,/g,""));
  149.  
  150.                 // Check for NaN's, and make sure debits are negative
  151.                 c1 = (isNaN(c1) ? 0 : c1);
  152.                 c2 = (isNaN(c2) ? 0 : (c2 > 0 ? -c2 : c2));
  153.                 c3 = (isNaN(c3) ? 0 : (c3 > 0 ? -c3 : c3));
  154.  
  155.                 // Make sure we are dealing with values rounded to the nearest cent before calculating, 
  156.                 c1 = parseFloat(c1.toFixed(2));
  157.                 c2 = parseFloat(c2.toFixed(2));
  158.                 c3 = parseFloat(c3.toFixed(2));
  159.  
  160.                 var temp = c1 + c2 + c3; 
  161.                 var cb = document.getElementById("total");
  162.                 cb.value = temp;
  163.                 currency(cb); 
  164.  
  165.             }                        
  166. //-------------------------------------------------------------------------------------------------------------------------------------------------            
  167.  
  168.     function clearit()
  169. {
  170. var a = document.getElementById('subtotal').value;
  171. var b = document.getElementById('cost_basis');
  172. var c = document.getElementById('total');
  173. var d = document.getElementById('taxable_income');
  174. var e = document.getElementById('fed_withhold');
  175. var f = document.getElementById('state_withhold');
  176.  
  177. b.value='';
  178. c.value='';
  179. d.value='';
  180. e.value='';
  181. f.value='';
  182. }
  183. //---------------------------------------------------------------------------------------------------------------------------------------------    
  184. function fedWithhold(){
  185.  
  186.     var a = document.getElementById("tax_code")
  187.                 if(((a.value == "457 Pension") || (a.value == "HR-10")) || (a.value == "TSA")  || (a.value == "Sepp IRA")){
  188.  
  189.     var c1 = parseFloat(document.getElementById("taxable_income").value.replace(/,/g,""));
  190.     c1 = (isNaN(c1) ? 0 : c1);
  191.     c1 = parseFloat(c1.toFixed(2));
  192.  
  193.  
  194.     var v = 20;
  195.     var p = 100;
  196.     var temp = c1 / p; 
  197.     var temp2 = temp * v; 
  198.  
  199.     var cb = document.getElementById('fed_withhold');
  200.     cb.value = temp2;
  201.     currency(cb);
  202.                 }
  203.  
  204.     var a = document.getElementById("tax_code")
  205.                 if((a.value == "IRA") || (a.value == "Non Qualified Annuity")|| (a.value == "Life/Disability")){
  206.  
  207.     var c1 = parseFloat(document.getElementById("taxable_income").value.replace(/,/g,""));
  208.     c1 = (isNaN(c1) ? 0 : c1);
  209.     c1 = parseFloat(c1.toFixed(2));
  210.  
  211.  
  212.     var v = 10;
  213.     var p = 100;
  214.     var temp = c1 / p; 
  215.     var temp2 = temp * v; 
  216.  
  217.     var cb = document.getElementById('fed_withhold');
  218.     cb.value = temp2;
  219.     currency(cb);
  220.                 }    
  221.  
  222.     var a = document.getElementById("tax_code")
  223.                 if (a.value == "Roth IRA"){
  224.  
  225.     var c1 = parseFloat(document.getElementById("taxable_income").value.replace(/,/g,""));
  226.     c1 = (isNaN(c1) ? 0 : c1);
  227.     c1 = parseFloat(c1.toFixed(2));
  228.  
  229.  
  230.     var v = 0;
  231.     var p = 100;
  232.     var temp = c1 / p; 
  233.     var temp2 = temp * v; 
  234.  
  235.     var cb = document.getElementById('fed_withhold');
  236.     cb.value = temp2;
  237.     currency(cb);            
  238.  
  239.  
  240.  
  241. }
  242. }
  243.  
  244. //--------------------------------------------------------------------------------------------------------------------------------------------------
  245.  
  246. function stateWithhold() {
  247.         var a = document.getElementById('state').value
  248.             b = document.getElementById('Yes')
  249.             n = document.getElementById('No')
  250.             c = parseFloat(document.getElementById("fed_withhold").value.replace(/,/g,""));
  251.             t = parseFloat(document.getElementById("taxable_income").value.replace(/,/g,""));
  252.             d = document.getElementById('tax_code')
  253.  
  254.             // State w/h %
  255.             r = 5.3,
  256.             q = 0,
  257.             u = 25, 
  258.             v = 10,
  259.             w = 4,
  260.             x = 5,
  261.             y = 21,
  262.             z = 8,
  263.             p = 100,
  264.             tax = 0.00,
  265.  
  266.         c = (isNaN(c) ? 0 : c);
  267.         c = c * 100; // Convert to integer for proper rounding
  268.  
  269.         t = (isNaN(t) ? 0 : t);
  270.         t = t * 100; // Convert to integer for proper rounding
  271.  
  272.         var limit = 100000; // Alter this for proper rounding, too
  273.         // California
  274.         if (a === "CA" && b.checked && c >= limit)  {
  275.             tax = ((c * v) / 10000).toFixed(2); // w/h amount
  276.  
  277.         document.getElementById("state_withhold").value = tax;
  278.         return false;
  279.  
  280.         calc5();
  281.         }
  282.         // Iowa
  283.         if ((a === "IA") && (b.checked)){  
  284.             tax = ((t * x) / 10000).toFixed(2); // w/h amount
  285.         }
  286.         calc5();
  287.         document.getElementById("state_withhold").value = tax;
  288.  
  289.         // Nebraska
  290.         if (a === "NE" && b.checked){  
  291.             tax = ((c * y) / 10000).toFixed(2); // w/h amount
  292.         }
  293.         calc5();
  294.         document.getElementById("state_withhold").value = tax;    
  295.  
  296.         // Oregon
  297.         if (a === "OR" && b.checked){  
  298.             tax = ((t * z) / 10000).toFixed(2); // w/h amount
  299.         }
  300.         calc5();
  301.         document.getElementById("state_withhold").value = tax;    
  302.  
  303.         // Maine
  304.         if (a === "ME" && b.checked){  
  305.             tax = ((t * x) / 10000).toFixed(2); // w/h amount
  306.         }
  307.         calc5();
  308.         document.getElementById("state_withhold").value = tax;
  309.  
  310.         // Vermont
  311.         if (a === "VT" && b.checked){  
  312.             tax = ((c * u) / 10000).toFixed(2); // w/h amount
  313.         }
  314.         calc5();
  315.         document.getElementById("state_withhold").value = tax;
  316.  
  317.         // Virginia
  318.         if (a === "VA" && b.checked){  
  319.             tax = ((t * w) / 10000).toFixed(2); // w/h amount
  320.         }
  321.         calc5();
  322.         document.getElementById("state_withhold").value = tax;
  323.  
  324.  
  325.         // Other States
  326.         if ( n.checked){  
  327.             tax = ((t * q) / 10000).toFixed(2); // w/h amount
  328.         }
  329.  
  330.         calc5();
  331.         document.getElementById("state_withhold").value = tax;
  332.     }
  333. //------------------------------------------------------------------------------------------------------------------------------------------------        
  334. function annunity(){
  335.  
  336.     var x = document.getElementById('state').value
  337.             b = document.getElementById('Yes')
  338.             t = parseFloat(document.getElementById('taxable_income').value.replace(/,/g,""));
  339.             s = document.getElementById('tax_code')
  340.  
  341.             r = 5.3,
  342.             v = 10,
  343.             tax = 0.00,
  344.  
  345.         t = (isNaN(t) ? 0 : t);
  346.         t = t * 100; // Convert to integer for proper rounding
  347.  
  348.  
  349.         // Massachusetts
  350.         if ((x === "MA") && (b.checked) && (s.value === "IRA" || "HR-10" || "TSA" || "Sepp IRA" || "457 Pension" || "Roth IRA"))
  351.         {
  352.  
  353.             tax = ((t * r) / 10000).toFixed(2); // w/h amount
  354.         }
  355.         calc5();
  356.         document.getElementById("state_withhold").value = tax;
  357.  
  358.  
  359.          if (x === "MA" && b.checked && s.value === "Life/Disability")
  360.             {
  361.             tax = ((t * v) / 10000).toFixed(2); // w/h amount
  362.             }
  363.         calc5();
  364.         document.getElementById("state_withhold").value = tax;
  365.  
  366. }
  367. </script>
  368. </head>
  369. <body>
  370. <form name="theform" method="post" action="" >
  371.   <table width="652" border="0" cellspacing="1" cellpadding="1" bgcolor="#C1E1E1" >
  372.     <tr>
  373.       <th  class="th" colspan="3">Check Request Worksheet</th>
  374.     </tr>
  375.     <tr>
  376.       <td  align="right" ></td>
  377.       <td></td>
  378.     </tr>
  379.   </table>
  380.   <table width="652" border="0" cellspacing="1" cellpadding="1" bgcolor="#C1E1E1" >
  381.     <tr >
  382.       <td  colspan="3"class="line">&nbsp;</td>
  383.     </tr>
  384.   </table>
  385.   <table width="655" border="0" cellspacing="0" cellpadding="0" bgcolor="#C1E1E1"   id="A" style="display:block">
  386.     <tr >
  387.       <td colspan="4"><table width="655" border="0" cellspacing="1" cellpadding="1" bgcolor="#C1E1E1"   >
  388.           <tr >
  389.             <td width="190" align="right">Base Cash Value:</td>
  390.             <td width="459"><input type="text" class="fill" name=""   id="base_cash_value"style="text-align:right" onblur="currency(this)"/></td>
  391.           </tr>
  392.           <tr>
  393.             <td align="right"> - Cost Basis:</td>
  394.             <td width="459"><input type="text" class="fill" name="cost_basis"  id="cost_basis" onkeyup="calc4(); "style="text-align:right" onblur="currency(this)"/></td>
  395.           </tr>
  396.           <tr>
  397.             <td width="186" align="right"><b>Taxable Income:</b></td>
  398.             <td width="459"><input type="text" class="fill" name="taxable_income"  id="taxable_income"  style="text-align:right"/></td>
  399.           </tr>
  400.         </table></td>
  401.     </tr>
  402.   </table>
  403.   </tr>
  404.   </tr>
  405.   <table width="655" border="0" cellspacing="0" cellpadding="0" bgcolor="#C1E1E1"   id="C" style="display:block">
  406.     <tr >
  407.       <td colspan="4"></td>
  408.     </tr>
  409.   </table>
  410.   </tr>
  411.   <table width="655" border="0" cellspacing="1" cellpadding="1" bgcolor="#C1E1E1"  id="D">
  412.     <tr>
  413.       <td align="right">Taxation:&nbsp;</td>
  414.       <td><select name="tax code"  id="tax_code" onchange="document.theform.showValueA.value=this.value;fedWithhold();calc5();">
  415.           <option value=""></option>
  416.           <option value="IRA">I</option>
  417.           <option value="HR-10">H</option>
  418.           <option value="Non Qualified Annuity">N</option>
  419.           <option value="TSA">O</option>
  420.           <option value="Sepp IRA">S</option>
  421.           <option value="457 Pension">P</option>
  422.           <option value="Roth IRA">Q</option>
  423.           <option value="Life/Disability">X</option>
  424.         </select>
  425.         &nbsp;
  426.         <input type="text" class="fill2" name="showValueA"  size="30"/></td>
  427.     </tr>
  428.     <tr>
  429.       <td align="right">Federal Withholding:</td>
  430.       <td width="458"><input type="text" class="fill" name="" id="fed_withhold" style="text-align:right" onkeyup="calc3();"onblur="currency(this)" />
  431.         &nbsp;(Account 271700700)</td>
  432.     </tr>
  433.     <tr>
  434.       <td align="right">Withhold:</td>
  435.       <td>&nbsp;
  436.         <input type="checkbox" id="Yes" onclick="stateWithhold();annunity();"/>
  437.         Yes &nbsp;
  438.         <input type="checkbox" id="No"  />
  439.         No 
  440.         &nbsp;&nbsp;&nbsp;State:&nbsp;
  441.         <select name="OBKey__181_1"  id="state" tabindex="30" onchange="stateWithhold();annunity();">
  442.           <option value=""> </option>
  443.           <option value="CA">CA </option>
  444.           <option value="IA">IA </option>
  445.           <option value="KS">KS </option>
  446.           <option value="MA">MA </option>
  447.           <option value="NE">NE </option>
  448.           <option value="OR">OR </option>
  449.           <option value="VT">VT </option>
  450.           <option value="VA">VA </option>
  451.         </select></td>
  452.       </td>
  453.     </tr>
  454.     <tr>
  455.       <td align="right">State Withholding:</td>
  456.       <td width="458"><input type="text" class="fill" name="" id="state_withhold"style="text-align:right" onkeyup="calc3();" onblur="currency(this)" />
  457.         &nbsp;(Account 271701100)</td>
  458.     </tr>
  459.     <tr>
  460.       <td align="right"><b>Check Total:</b></td>
  461.       <td width="458"><input type="text" class="fill" name=""id="total" style="text-align:right" onblur"currency(this)"/>
  462.     </tr>
  463.     <tr>
  464.       <td  colspan="3"align="center"><input type="submit" value="Submit" name="OBBtn_Yes">
  465.     </tr>
  466.   </table>
  467. </form>
  468. </body>
  469. </html>
Attached Images
File Type: jpg screenshot.jpg (1.9 KB, 311 views)
Sep 15 '09 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
Skimming through all of your code is a lot of work and I don't expect many of the volunteers here are going to take the time to read through all of your code to figure out what you're talking about.

Please only post the code that is relevant to your problem...
(What are the similar functions?)

And also please post code in code tags.

-Frinny
Sep 15 '09 #2

Post your reply

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