practice-time-shopping-list/script/app.js

39 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2022-12-04 23:21:40 +00:00
document.addEventListener("DOMContentLoaded", function () {
const lista = []
const form = document.querySelector("shopping-form");
const itenInput = document.querySelector("shopping-form-item-input");
const qualitityInput = document.querySelector(".shopping-form-quality-input");
const incrementeButton = document.querySelector(".incremente-button");
const decrementeButton = document.querySelector(".decremente-button");
incrementeButton.addEventListener("click", incrementeQuantity);
decrementeButton.addEventListener("click", decrementeQuantity);
form.addEventListener("submit", addItemToList);
function incrementeQuantity() {
const currentValue = Number(qualitityInput.value);
const newValue = currentValue + 1;
qualitityInput.value = newValue;
}
function decrementeQuantity() {
const currentValue = Number(qualitityInput.value);
const newValue = currentValue - 1;
if (newValue > 0) {
qualitityInput.value = newValue;
}
}
function addItemToList(event){
event.preventDefault();
const itemName = event.target["item-name"].value;
console.log(itemName);
}
});