WED201c_-_SP_2023_-_PE_-_01_138.webp
thổ dân IT

WED201c_-_SP_2023_-_PE_-_01_138.webp

1
**/
2
* Calculate the total amount of price of selected items
3
* Push seleted items' name into the right column
4
*
5
6
7
8
9
0
1
2
3
4
5
6
7
}
8
}
9
20
1
2
3
4
*/
function CalTotal() {
let totalAmount = 0;
allItems = document.getElementsByClassName('selection'); //Querry all checkbox item
allItemsName = document.getElementsByClassName('name'); //Querry all items' name selectedItems = []; // Store all choosen items
for (let i = 0; i < allItems.length; i++) {
current = allItems[i];
if (current.checked) {
selectedItems.push(allItemsName[i].innerHTML);
totalAmount += Number(current.value);
// Querry container of selected items to append selected item into selectedItemsContainer = document.getElementById('selected-items');selectedItemsContainer.textContent = ""; // Clear old orders
selectedItems.forEach(name => {
selectedItemsContainer.innerHTML += ("<span>" + name + "</span><br>");
5
});
6
7
totalAmount Container = document.getElementById('total-amount');
8
totalAmountContainer.innerHTML = "<h3>TotalAmount:"+ totalAmount + "$</h3>";
9FUO
Chưa có bình luận nào.

Thông tin

Category
WED201c
Thêm bởi
thổ dân IT
Ngày thêm
Lượt xem
162
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom