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

Execute calculation code if checkbox is checked

P: 6
I need this to charge sales tax on if oklahoma resident is checked



Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" > 
  4. <head>
  5.  
  6.     <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  7.     <title>Shortpockets Computers & More</title>
  8.  
  9. <script language="javascript">
  10.  
  11.     <!--
  12.         //funtion to summarize order
  13.             function WriteSummary()
  14.     {
  15.  
  16.         var currQuantity = document.frmOrderItem.txtQuantity.value;
  17.         if (currQuantity == "")
  18.  
  19.     {
  20.  
  21.         alert("Please enter a value for Desired ."); 
  22.  
  23.  
  24.     }
  25.  
  26.         else if (parseFloat(currQuantity) <=0)
  27.         "Quantity that is greater than 0.");
  28.  
  29.     {
  30.  
  31.         alert("Please enter a value for Desired " +
  32.         "Quantity that is greater than 0."); 
  33.  
  34.     }
  35.     else
  36.     }
  37.      function chkStatus(Oklahoma)
  38.      var Oklahoma = chkBox + "ON"
  39.     {
  40. var salesTax = document.frmOrderItem.txtQuantity.value *();
  41.          if (chkBox = "ON")then
  42.         { 
  43.  
  44.         alert("document.frmOrderItem.txtQuantity.value * .045");
  45.      }
  46.  
  47.         else (chkBox = "OFF")
  48.         {
  49.      alert("document.frmOrderItem.txtSalesTax.value * .0");
  50.  
  51.  
  52. }
  53.         else 
  54.     {    
  55.  
  56.  
  57.         var subTotal = new Number();
  58.         var salesTax = new Number ();
  59.         var orderTotal = new Number();
  60.  
  61.  
  62.  
  63.         subTotal =
  64.  
  65.         document.frmOrderItem.txtQuantity.value * 45.99;
  66.         document.frmOrderItem.txtSubTotal.value = "$ " + subTotal.toFixed(2) ;
  67.         salesTax = subTotal * .045;
  68.         document.frmOrderItem.txtTax.value = "$ " + salesTax.toFixed(2);
  69.         orderTotal = subTotal + salesTax;
  70.         document.frmOrderItem.txtOrderTotal.value = "$ " + orderTotal.toFixed(2);
  71.     }
  72.  
  73.  
  74.         //-->
  75. </script>
  76.  
  77. </head>
  78. <body>
  79.  
  80.  
  81. <!--table displaying Sp and page title -->
  82. <table width="80%" align="center">
  83. <tr>
  84. <td><img src="case3.gif" width="200" height="174" align="right" style="width : 200px; height: 174px"></td>
  85. <td><h2><b></b>&nbsp;&nbsp;Products</h2></td>
  86. </tr>
  87. </table>
  88. <!--table and form displaying inventory data -->
  89. <form name="frmOrderItem" action="">
  90. <p></p>
  91. <table width="80%" border="5" cellspacing="3" cellpadding="5" align="center">
  92. <tr>
  93. <th width="20%">Selection</th>
  94. <th width="20%">Item</th>
  95. <th width="20%">Type</th>
  96. <th width="20%">Price</th>
  97. <th width="20%">In Stock?</th>
  98. </tr> 
  99. <tr><td align="center"><input type="radio" checked name="optInvid" value="YES"></td>
  100. <td align="center">Case</td>
  101. <td align="center">Mid-t</td>
  102. <td align="center">$45.99</td>
  103. <td align="center">Yes</td></tr>
  104. </table><p></p>
  105.  
  106. <table width=80% border="0" cellspacing="3" cellpadding="5" align="center">    
  107. <tr>
  108.     <td align="center"><input type="checkbox" name="chkStatus" id= "Oklahoma" value="ON"/>Oklahoma residents check here</td>
  109. </tr>
  110.  
  111. </table><p></p>
  112. <!--table displaying form controls -->
  113. <table width="80%" cellspacing="3" cellpadding="5" align="center">
  114. <tr>
  115. <td width="70%"><big>Desired Quantity</big> 
  116. <input type="text" name="txtQuantity" size="10" ></td>
  117. <td align="right" width="15%"><input type="button" value="Submit Order" onclick="WriteSummary()"></td>
  118. </tr>
  119. </table><p></p>
  120. <!-- table summarizing order -->
  121. <p></p>
  122. <table width="80%" align="center" border="2" ID="Table1">
  123.     <tr><td align="right">Subtotal:</td><td><input type="text" name="txtSubTotal"></td></tr>
  124.     <tr><td align="right">Tax:</td><td><input type="text" name="txtTax"></td></tr>
  125.     <tr><td align="right">Order Total:</td><td><input type="text" name="txtOrderTotal"></td></tr>
  126. </table>
  127.  
  128. </form>
  129. </body></html>
  130.  
Sep 29 '06 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Use the checkbox's checked property. If it's checked (i.e. true), then add the sales tax, e.g.
Expand|Select|Wrap|Line Numbers
  1. if (chkbox.checked) {
  2. // code to add sales tax...
  3. }
May 22 '08 #2

Post your reply

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