39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
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);
|
|
|
|
}
|
|
|
|
});
|