Guest User

Untitled

a guest
May 9th, 2023
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Order Form</title>
  5. <link rel="stylesheet" href="style.css">
  6. <script>
  7. const form = document.querySelector('#order-form');
  8. const productSelects = form.querySelectorAll('select[name="product"]');
  9. const quantityInputs = form.querySelectorAll('input[name^="quantity"]');
  10. const shippingRadios = form.querySelectorAll('input[name="shipping"]');
  11. const stateSelect = form.querySelector('select[name="state"]');
  12. const submitBtn = form.querySelector('button[type="submit"]');
  13. const orderSummary = document.querySelector('#order-summary');
  14.  
  15. const products = [ { name: 'Product 1', price: 10.99 }, { name: 'Product 2', price: 8.99 }, { name: 'Product 3', price: 12.99 }];
  16.  
  17. const shippingOptions = [ { name: 'Standard', price: 4.99 }, { name: 'Express', price: 9.99 }, { name: 'Overnight', price: 14.99 }];
  18.  
  19. const taxRates = { 'KY': 0.06, 'OH': 0.0575, 'other': 0 };
  20. const summary = `
  21. <h2>Order Summary</h2>
  22. <p>Your order was successfully placed on ${date}.</p>
  23. <table>
  24. <thead>
  25. <tr>
  26. <th>Product</th>
  27. <th>Quantity</th>
  28. <th>Price</th>
  29. </tr>
  30. </thead>
  31. <tbody>
  32. ${productsList}
  33. </tbody>
  34. </table>
  35. <p>Tax: $${tax.toFixed(2)}</p>
  36. <p>Shipping: $${shippingCost.toFixed(2)}</p>
  37. <p>Total: $${total.toFixed(2)}</p>
  38. `;
  39.  
  40. form.addEventListener('submit', (event) => {
  41. event.preventDefault();
  42. orderSummary.innerHTML = summary;}
  43.  
  44. const quantities = Array.from(quantityInputs).map(input => parseInt(input.value) || 0);
  45. if (quantities.every(quantity => quantity === 0)) {
  46. alert('Please select at least 1 product to order.');
  47. return;
  48. }
  49.  
  50. const selectedShipping = Array.from(shippingRadios).find(radio => radio.checked);
  51. if (!selectedShipping) {
  52. alert('Please select a shipping option.');
  53. return;
  54. }
  55.  
  56. const selectedState = stateSelect.value;
  57. if (selectedState === '') {
  58. alert('Please select a state.');
  59. return;
  60. }
  61.  
  62. const subtotal = products.reduce((total, product, index) => total + product.price * quantities[index], 0);
  63. const taxRate = taxRates[selectedState] || taxRates['other'];
  64. const tax = subtotal * taxRate;
  65. const shippingCost = shippingOptions.find(option => option.name === selectedShipping.value).price;
  66. const total = subtotal + tax + shippingCost;
  67.  
  68. // Build order summary
  69. const date = new Date().toLocaleDateString();
  70. const productsList = products.map((product, index) => {
  71. const quantity = quantities[index];
  72. const price = product.price.toFixed(2);
  73. return `
  74. <tr>
  75. <td>${product.name}</td>
  76. <td>${quantity}</td>
  77. <td>$${price}</td>
  78. </tr>
  79. `;
  80. }).join('');
  81.  
  82.  
  83. </script>
  84. </head>
  85. <body>
  86. <nav>
  87. <ul>
  88. <li><a href="index.html">Home</a></li>
  89. <li><a href="order.html">Order Form</a></li>
  90. </ul>
  91. </nav>
  92. <header>
  93. <img src="logo.png" alt="Company Logo">
  94. <h1>Order Form</h1>
  95. </header>
  96. <main>
  97. <div id="order-summary"></div>
  98.  
  99. <form id="order-form" >
  100. <h2>Customer Information</h2>
  101. <label for="customer-name">Name:</label>
  102. <input type="text" id="customer-name" name="customer-name" required>
  103.  
  104. <label for="street-address">Street Address:</label>
  105. <input type="text" id="street-address" name="street-address" required>
  106.  
  107. <label for="city">City:</label>
  108. <input type="text" id="city" name="city" required>
  109.  
  110. <label for="state">State:</label>
  111. <select id="state" name="state" required>
  112. <option value="">Select a state</option>
  113. <option value="AL">Alabama</option>
  114. <option value="AK">Alaska</option>
  115. <option value="AZ">Arizona</option>
  116. <!-- add all 50 states here -->
  117. <option value="AR">Arkansas</option>
  118. <option value="CA">California</option>
  119. <option value="CO">Colorado</option>
  120. <option value="CT">Conneticut</option>
  121. <option value="DE">Delaware</option>
  122. <option value="FL">Florida</option>
  123. <option value="GA">Georgia</option>
  124. <option value="HI">Hawaii</option>
  125. <option value="ID">Idaho</option>
  126. <option value="IL">Illinois</option>
  127. <option value="IN">Indiana</option>
  128. <option value="IA">Iowa</option>
  129. <option value="KS">Kansas</option>
  130. <option value="KY">Kentucky</option>
  131. <option value="LA">Louisiana</option>
  132. <option value="ME">Maine</option>
  133. <option value="MD">Maryland</option>
  134. <option value="MA">Massachussetts</option>
  135. <option value="MI">Michigan</option>
  136. <option value="MN">Minnesota</option>
  137. <option value="MS">Mississippi</option>
  138. <option value="MO">Missouri</option>
  139. <option value="MT">Montana</option>
  140. <option value="NE">Nebraska</option>
  141. <option value="NV">Nevada</option>
  142. <option value="NH">New Hampshire</option>
  143. <option value="NJ">New Jersey</option>
  144. <option value="NM">New Mexico</option>
  145. <option value="NY">New York</option>
  146. <option value="NC">North Carolina</option>
  147. <option value="ND">North Dakota</option>
  148. <option value="OH">Ohio</option>
  149. <option value="OK">Oklahoma</option>
  150. <option value="OR">Oregon</option>
  151. <option value="PA">Pennsylvania</option>
  152. <option value="RI">Rhode Island</option>
  153. <option value="SC">South Carolina</option>
  154. <option value="SD">South Dakota</option>
  155. <option value="TN">Tennessee</option>
  156. <option value="TX">Texas</option>
  157. <option value="UT">Utah</option>
  158. <option value="VT">Vermont</option>
  159. <option value="VA">Virginia</option>
  160. <option value="WA">Washington</option>
  161. <option value="WV">West Virginia</option>
  162. <option value="WI">Wisconsin</option>
  163. <option value="WY">Wyoming</option>
  164. </select>
  165.  
  166. <label for="zip-code">Zip Code:</label>
  167. <input type="text" id="zip-code" name="zip-code" required>
  168.  
  169. <h2>Products</h2>
  170. <p>Please enter the quantity of each product you want to order:</p>
  171. <label for="product1">Product 1:</label>
  172. <input type="number" id="product1" name="product1" min="0">
  173.  
  174. <label for="product2">Product 2:</label>
  175. <input type="number" id="product2" name="product2" min="0">
  176.  
  177. <label for="product3">Product 3:</label>
  178. <input type="number" id="product3" name="product3" min="0">
  179.  
  180. <h2>Shipping</h2>
  181. <p>Please select a shipping option:</p>
  182. <label>
  183. <input type="radio" name="shipping" value="overnight" required>
  184. Overnight - $15.00
  185. </label>
  186. <label>
  187. <input type="radio" name="shipping" value="2day" required>
  188. 2-Day - $10.00
  189. </label>
  190. <label>
  191. <input type="radio" name="shipping" value="standard" required>
  192. Standard - $5.00
  193. </label>
  194.  
  195. <button type="submit">Place Order</button>
  196. </form>
  197. </main>
  198.  
  199. <footer>
  200. <p>&copy; 2023 My Company Name | EKU | CSC 160 Final Project</p>
  201. </footer>
  202. </body>
  203. </html>
  204.  
Advertisement
Add Comment
Please, Sign In to add comment