-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
62 lines (59 loc) · 2 KB
/
script.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let submit = document.querySelector("#submit");
let activeContainer = document.querySelector(".container");
let itemName = document.getElementById("name");
let image = document.getElementById("choose-file");
let number = document.getElementById("number");
let amount = document.getElementById("amount");
let date = document.getElementById("date");
let containContainer = document.getElementById("contain-container");
submit.addEventListener("click", () => {
alert(itemName)
if (
itemName.value.trim() !== "" &&
amount.value.trim() !== "" &&
number.value.trim() !== "" &&
date.value.trim() !== "" &&
itemName.value.trim() !== ""
) {
active();
itemName.value = "";
amount.value = "";
date.value = "";
number.value = "";
image.value = "";
}
});
const active = () => {
let div = document.createElement("div");
div.classList.add("container");
let img = document.createElement("img");
img.src = image;
let paraOne = document.createElement("p");
paraOne.setAttribute("id", "name-active");
paraOne.innerText = itemName.value;
let paraTwo = document.createElement("p");
paraTwo.setAttribute("id", "number-active");
paraTwo.innerText = number.value;
let paraThree = document.createElement("p");
paraThree.setAttribute("id", "amount-active");
paraThree.innerText = amount.value;
let paraFour = document.createElement("p");
paraFour.setAttribute("id", "date-active");
paraFour.innerText = date.value;
let editItem = document.createElement("li");
editItem.classList.add("edit");
editItem.setAttribute("onclick", "edit");
editItem.innerText = "edit";
let deleteItem = document.createElement("li");
deleteItem.classList.add("delete");
deleteItem.setAttribute("onclick", "delete");
deleteItem.innerText = "delete";
div.appendChild(img);
div.appendChild(paraOne);
div.appendChild(paraTwo);
div.appendChild(paraThree);
div.appendChild(paraFour);
div.appendChild(editItem);
div.appendChild(deleteItem);
containContainer.appendChild(div);
};