//index.html Shipping form
///index.js let shippingmethod = document.getElementById("shipping"); let addbtn = document.getElementById("addbtn"); let resetbtn = document.getElementById("resetbtn"); let submitbtn = document.getElementById("submitbtn"); let list = document.getElementById("myList"); let shipErr = document.getElementById("shipErr"); let costErr = document.getElementById("costErr"); let addCostErr = document.getElementById("addCostErr"); const MAX_COST = 10000; const MAX_ADD_COST = MAX_COST * 0.10; // dropdown options added dynamically let shippingOptions = ["USPS", "Pickup", "Fedx", "Other"]; // load dropdown on page load window.onload = function () { loadDropdown(); rebuildList(); }; // load dropdown dynamically function loadDropdown() { shippingmethod.innerHTML = "";
} // store list let items = JSON.parse(localStorage.getItem("items")) || []; // ADD BUTTON addbtn.addEventListener("click", function () {
}); // rebuild table list function rebuildList() { list.innerHTML = "";
} // reset resetbtn.addEventListener("click", function () { items = []; localStorage.removeItem("items"); loadDropdown(); rebuildList(); clearErrors(); }); // submit validation submitbtn.addEventListener("click", function () { clearErrors(); if (items.length === 0) { shipErr.innerText = "Please add at least one record before submit"; return; } window.location.href = "summary.html"; }); // helper function clearErrors() { shipErr.innerText = ""; costErr.innerText = ""; addCostErr.innerText = ""; } ///summary.html
|
<button id="backbtn">Go Back</button>
<!-- External JS file -->
<script src="summary.js"></script>
///summary.js
let tableHead = document.getElementById("summaryHead"); let tableBody = document.getElementById("summaryList"); let backbtn = document.getElementById("backbtn");
// get stored data let items = JSON.parse(localStorage.getItem("items")) || [];
// hide header if no data if (items.length === 0) { tableHead.style.display = "none"; }
// build table rows items.forEach(item => {
let tr = document.createElement("tr");
// Shipping Method
let tdMethod = document.createElement("td");
tdMethod.innerText = item.method;
// Cost
let tdCost = document.createElement("td");
tdCost.innerText = "$" + item.cost;
// Additional Cost
let tdAddCost = document.createElement("td");
tdAddCost.innerText = item.addCost !== "" ? "$" + item.addCost : "-";
tr.appendChild(tdMethod);
tr.appendChild(tdCost);
tr.appendChild(tdAddCost);
tableBody.appendChild(tr);
});
// go back button backbtn.addEventListener("click", function () { window.location.href = "index.html"; });
///style.css
/* page setup / body { font-family: Arial, sans-serif; margin: 20px; text-align: center; / centers text and inline elements */ }
/* headings */ h1, h2 { margin-bottom: 15px; }
/* inputs and dropdown */ select, input { width: 200px; padding: 5px; margin-bottom: 10px; }
/* buttons */ button { padding: 5px 10px; margin: 10px 5px; cursor: pointer; }
/* table / table { margin: 15px auto; / centers table horizontally */ border-collapse: collapse; width: 70%; }
/* table header */ th { background-color: #eaeaea; }
/* table cells / th, td { border: 1px solid black; padding: 8px; text-align: center; / center text inside table */ }
/* remove button inside table */ td button { padding: 3px 6px; }
/* submit & back button spacing / #submitbtn, #backbtn { display: block; margin: 20px auto; / centers buttons / } / hide number arrows */ input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* input[type=number] { -moz-appearance: textfield; } */
/* validation text */ #shipErr, #costErr, #addCostErr { font-size: 12px; margin-bottom: 8px; }