-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
67 lines (67 loc) · 2.79 KB
/
index.html
File metadata and controls
67 lines (67 loc) · 2.79 KB
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
63
64
65
66
67
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class = "container mx-20 bg-dark w-50 p-3">
<h1 class = "text-white">Inventory Management</h1>
<div class = "mt-5 text-white">
<label for = "name">Name:</label><br>
<input type ="text" name = "name" id ="name" class ="form-control">
<label for = "qty">Quantity:</label><br>
<input type ="number" name = "qty" id ="qty" class ="form-control">
<label for = "price">Price:</label><br>
<input type ="number" name = "price" id ="price" class ="form-control">
<button class = "btn btn-success w-100 mt-3" id = "edit" onclick = "edit()">Edit</button>
<button class = "btn btn-success w-100 mt-3" id = "submit" onclick = "addItem()">Submit</button>
</div>
<table class = "table table-hover table-bordered mt-3" id = "table">
<tr>
<th>Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Action</th>
</tr>
</table>
</div>
<script>
function addItem(){
let name = document.getElementById('name').value;
let qty = document.getElementById('qty').value;
let price = document.getElementById('price').value;
let table = document.getElementById("table");
let r = table.insertRow();
r.innerHTML=`<td class = 'names'>${name}</td>
<td class = 'qtys'>${qty}</td>
<td class = 'prices'>${price}</td>
<td class = 'cost'><button onclick = 'this.parentElement.parentElement.remove()' class="btn btn-danger">Remove</button>`;
document.getElementById('name').value='';
document.getElementById('qty').value='';
document.getElementById('price').value = '';
}
function edit(){
let names = document.getElementsByClassName('names');
let qtys = document.getElementsByClassName('qtys');
let prices = document.getElementsByClassName('prices');
let cost = document.getElementsByClassName('cost');
let name = document.getElementById('name').value;
let qty = document.getElementById('qty').value;
let price = document.getElementById('price').value;
for(let i=0;i<names.length;i++){
if(names[i].innerHTML == name){
qtys[i].innerHTML = qty;
prices[i].innerHTML = prices;
cost[i].innerHTML = qty*prices;
alert("Edited")
return;
}
}
alert("Item not found!")
}
</script>
</body>
</html>