-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (24 loc) · 785 Bytes
/
Copy pathscript.js
File metadata and controls
26 lines (24 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
document.getElementById("customerForm").addEventListener("submit", function(e) {
e.preventDefault();
const formData = new FormData(e.target);
const data = {};
for (let [key, value] of formData.entries()) {
if (data[key]) {
if (!Array.isArray(data[key])) data[key] = [data[key]];
data[key].push(value);
} else {
data[key] = value;
}
}
data.timestamp = new Date().toISOString();
let customers = JSON.parse(localStorage.getItem("customers") || "[]");
customers.push(data);
localStorage.setItem("customers", JSON.stringify(customers));
alert("Customer created successfully!");
e.target.reset();
});
function cancelForm() {
if (confirm("Are you sure you want to cancel?")) {
document.getElementById("customerForm").reset();
}
}