Execute calculation code if checkbox is checked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcyb
    New Member
    • Sep 2006
    • 6

    Execute calculation code if checkbox is checked

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



    Code:
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head>
     
    	<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    	<title>Shortpockets Computers & More</title>
     
    <script language="javascript">
     
    	<!--
    		//funtion to summarize order
    			function WriteSummary()
    	{
     
    		var currQuantity = document.frmOrderItem.txtQuantity.value;
    		if (currQuantity == "")
     
    	{
     
    		alert("Please enter a value for Desired ."); 
     
     
    	}
     
    		else if (parseFloat(currQuantity) <=0)
    		"Quantity that is greater than 0.");
     
    	{
     
    		alert("Please enter a value for Desired " +
    		"Quantity that is greater than 0."); 
     
    	}
    	else
    	}
    	 function chkStatus(Oklahoma)
    	 var Oklahoma = chkBox + "ON"
    	{
    var salesTax = document.frmOrderItem.txtQuantity.value *();
    		 if (chkBox = "ON")then
    		{ 
     
    		alert("document.frmOrderItem.txtQuantity.value * .045");
    	 }
     
    		else (chkBox = "OFF")
    		{
    	 alert("document.frmOrderItem.txtSalesTax.value * .0");
     
     
    }
    		else 
    	{	
     
     
    		var subTotal = new Number();
    		var salesTax = new Number ();
    		var orderTotal = new Number();
     
     
     
    		subTotal =
     
    		document.frmOrderItem.txtQuantity.value * 45.99;
    		document.frmOrderItem.txtSubTotal.value = "$ " + subTotal.toFixed(2) ;
    		salesTax = subTotal * .045;
    		document.frmOrderItem.txtTax.value = "$ " + salesTax.toFixed(2);
    		orderTotal = subTotal + salesTax;
    		document.frmOrderItem.txtOrderTotal.value = "$ " + orderTotal.toFixed(2);
    	}
     
     
    		//-->
    </script>
     
    </head>
    <body>
     
     
    <!--table displaying Sp and page title -->
    <table width="80%" align="center">
    <tr>
    <td><img src="case3.gif" width="200" height="174" align="right" style="width : 200px; height: 174px"></td>
    <td><h2><b></b>&nbsp;&nbsp;Products</h2></td>
    </tr>
    </table>
    <!--table and form displaying inventory data -->
    <form name="frmOrderItem" action="">
    <p></p>
    <table width="80%" border="5" cellspacing="3" cellpadding="5" align="center">
    <tr>
    <th width="20%">Selection</th>
    <th width="20%">Item</th>
    <th width="20%">Type</th>
    <th width="20%">Price</th>
    <th width="20%">In Stock?</th>
    </tr> 
    <tr><td align="center"><input type="radio" checked name="optInvid" value="YES"></td>
    <td align="center">Case</td>
    <td align="center">Mid-t</td>
    <td align="center">$45.99</td>
    <td align="center">Yes</td></tr>
    </table><p></p>
     
    <table width=80% border="0" cellspacing="3" cellpadding="5" align="center">	
    <tr>
    	<td align="center"><input type="checkbox" name="chkStatus" id= "Oklahoma" value="ON"/>Oklahoma residents check here</td>
    </tr>
     
    </table><p></p>
    <!--table displaying form controls -->
    <table width="80%" cellspacing="3" cellpadding="5" align="center">
    <tr>
    <td width="70%"><big>Desired Quantity</big> 
    <input type="text" name="txtQuantity" size="10" ></td>
    <td align="right" width="15%"><input type="button" value="Submit Order" onclick="WriteSummary()"></td>
    </tr>
    </table><p></p>
    <!-- table summarizing order -->
    <p></p>
    <table width="80%" align="center" border="2" ID="Table1">
    	<tr><td align="right">Subtotal:</td><td><input type="text" name="txtSubTotal"></td></tr>
    	<tr><td align="right">Tax:</td><td><input type="text" name="txtTax"></td></tr>
    	<tr><td align="right">Order Total:</td><td><input type="text" name="txtOrderTotal"></td></tr>
    </table>
     
    </form>
    </body></html>
    Last edited by Niheel; Sep 30 '06, 04:41 PM.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use the checkbox's checked property. If it's checked (i.e. true), then add the sales tax, e.g.
    [code=javascript]if (chkbox.checked ) {
    // code to add sales tax...
    }[/code]

    Comment

    Working...