Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>JohnCenaNew to Visual Studio Code? Get it now.
JohnCena

JohnCena

johncena

|
1 install
| (0) | Free
You can’t see me.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

//index.html

first variable

Shipping form

<br>

<input type="number" id="cost" placeholder="Cost">
<div id="costErr" style="color:red;"></div>

<br>

<input type="number" id="Acost" placeholder="Additional Cost">
<div id="addCostErr" style="color:red;"></div>

<br>

<button id="addbtn">Add</button>
<button id="resetbtn">Reset</button>

<table border="1">
    <thead id="tableHead">
        <tr>
            <th>Shipping Method</th>
            <th>Cost</th>
            <th>Additional Cost</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody id="myList"></tbody>
    </table>

    <button id="submitbtn">Submit</button>



    <script src="index.js"></script>
</body>

///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 = "";

let defaultOpt = document.createElement("option");
defaultOpt.text = "Choose option";
defaultOpt.value = "";
shippingmethod.add(defaultOpt);

shippingOptions.forEach(opt => {
    let option = document.createElement("option");
    option.text = opt;
    option.value = opt;
    shippingmethod.add(option);
});

}

// store list let items = JSON.parse(localStorage.getItem("items")) || [];

// ADD BUTTON addbtn.addEventListener("click", function () {

clearErrors();

let cost = document.getElementById("cost").value;
let ADDcost = document.getElementById("Acost").value;
let valid = true;

// shipping validation
if (shippingmethod.value === "") {
    shipErr.innerText = "Please select shipping method";
    valid = false;
}

// cost validation
if (cost === "") {
    costErr.innerText = "Cost is required";
    valid = false;
} else if (cost <= 0 || cost > MAX_COST) {
    costErr.innerText = "Cost must be between 1 and 10000";
    valid = false;
}

// additional cost validation
if (ADDcost !== "" && ADDcost > MAX_ADD_COST) {
    addCostErr.innerText = "Additional cost cannot exceed 1000";
    valid = false;
}

if (!valid) return;

let obj = {
    method: shippingmethod.value,
    cost: Number(cost).toFixed(2),
    addCost: ADDcost ? Number(ADDcost).toFixed(2) : ""
};

items.push(obj);
localStorage.setItem("items", JSON.stringify(items));

shippingmethod.remove(shippingmethod.selectedIndex);
rebuildList();

document.getElementById("cost").value = "";
document.getElementById("Acost").value = "";

});

// rebuild table list function rebuildList() { list.innerHTML = "";

let tableHead = document.getElementById("tableHead");
tableHead.style.display = items.length === 0 ? "none" : "";

items.forEach((item, i) => {
    let tr = document.createElement("tr");

    tr.innerHTML = `
        <td>${item.method}</td>
        <td>$${item.cost}</td>
        <td>${item.addCost ? "$" + item.addCost : "-"}</td>
        <td><button>Remove</button></td>
    `;

    tr.querySelector("button").addEventListener("click", function () {
        items.splice(i, 1);
        localStorage.setItem("items", JSON.stringify(items));
        loadDropdown();
        rebuildList();
    });

    list.appendChild(tr);
});

}

// 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

Shipping Summary
<h2>Shipping Summary</h2>

<table border="1">
<thead id="summaryHead">
    <tr>
        <th>Shipping Method</th>
        <th>Cost</th>
        <th>Additional Cost</th>
    </tr>
</thead>
<tbody id="summaryList">
    <!-- rows added dynamically -->
</tbody>
<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; }

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft