Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <center>
<div class ="form">
		<h2> Sales Tax Calculator</h5>
		<form name="orderform" id="orderform">
		<table>
</div>
  <tr><th>
   <label>Product: </label>
  </th>
  <th scope="row">
   <div align="left">
    <label><span>$</span></label>
    <input name="price" type="text" id="price" size="10">
   </div>
  </th>

  
  <tr><th>
   <label>Quantity</label>
  </th>
  <th scope="row">
   <div align="left">
    <label><span>#</span></label>
    <input name="quantity" type="text" id="quantity" size="10">
   </div>
  </th>
 
  <tr><th>
   <label>Subtotal:</label>
  </th>
  <th scope="row">   
   <div align="left">
    <label>$</label>
    <input name="subtotal" type="text" id="subtotal" onFocus="this.form.elements[1].focus()" size="10"> &nbsp;&nbsp;
    <input name="subBtn" onClick="subTotal();" type="button" id="subBtn" value="Subtotal">
   </div>
  </th>
 </tr>
  
   <tr><th>
   <label>Tax:</label>
  </th>
   <th scope="row">
   <div align="left">
    <label>$</label>
     <input name="salestax" type="text" id="salestax" onFocus="this.form.elements[1].focus()" size="10"> &nbsp;&nbsp;               
     <input name="taxBtn" onClick="calculateTax();" type="button" id="taxBtn" value="Tax">  
   </div>
  </th>
 </tr>
 
  <tr><th>
   <label>Total:</label>
  </th>
  <th scope="row">
   <div align="left">
    <label>$</label>
    <input name="gtotal" type="text" id="gtotal" onFocus="this.form.elements[2].focus()" size="10"> &nbsp;&nbsp;
    <input name="gtotalBtn" onClick="grandTotal();" type="button" id="gtotalBtn" value="Calculate Order">
   </div>
  </th>
 </tr>
</table>
</form>      
</div>
</center>
              
            
!

CSS

              
                table{
  border-style: solid;
  border-color: black;
  border-width: 5px;
  border-radius: 5px;
  background-color: silver;
}
#subBtn{
  border-style: solid;
  border-color: black;
  border-width: 2px;
  border-radius: 5px;
}
#taxBtn{
  border-style: solid;
  border-color: black;
  border-width: 2px;
  border-radius: 5px;
}
#gtotalBtn{
  border-style: solid;
  border-color: black;
  border-width: 2px;
  border-radius: 5px;
}




              
            
!

JS

              
                function subTotal() {
  var price = document.orderform.price.value;
  var quantity = document.orderform.quantity.value;
  productPrice = price * quantity;
  document.orderform.subtotal.value = productPrice.toFixed(2);
  return productPrice;
}
//calculateTax() takes result of subTotal function but has to refer to the result to move forward as opposed to the previous function
//.toFixed() is the decimal points
function calculateTax() {
  //var subTotal = document.orderform.subtotal.value; OR for dryer code:
  var subtotal = subTotal();
  var stax = 0.03;
    tax = subtotal * stax;
  document.orderform.salestax.value = tax.toFixed(3);
  return tax;
}
//takes the HTML output results from the previous two functions and adds them together. 
function grandTotal() {
  var subtotal = subTotal();
  var tax = calculateTax();
  document.orderform.subtotal.value = subtotal.toFixed(2);
  document.orderform.salestax.value = tax.toFixed(2);
  var gtotal = subtotal + tax;
  document.orderform.gtotal.value = gtotal.toFixed(2);
}
              
            
!
999px

Console