Candle/plusminusbutton.js

90 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-05-11 03:32:37 +02:00
var inputNumber = document.getElementsByClassName('input-group-field');
if (window.location.pathname.includes("/warenkorb.html")) {
document.addEventListener("DOMContentLoaded", function () {
$(window).on('load',function() {
2023-05-24 22:15:21 +02:00
for(var y = 0;y<inputNumber.length;y++)
{
showValue(inputNumber[y]);
}
2023-05-11 03:32:37 +02:00
2023-05-24 22:15:21 +02:00
var minusButton = document.getElementsByClassName("fa fa-minus");
var plusButton = document.getElementsByClassName("fa fa-plus");
2023-05-11 03:32:37 +02:00
//Dieser Code Block gehört zur Warenkorb Datei
2023-05-24 22:15:21 +02:00
for(var i = 0;i<plusButton.length;i++)
{
2023-05-11 03:32:37 +02:00
2023-05-24 22:15:21 +02:00
var button = plusButton[i]
2023-05-11 03:32:37 +02:00
2023-05-24 22:15:21 +02:00
button.addEventListener('click', incrmenetValue)
}
for(var j = 0;j<minusButton.length;j++)
{
var button1 = minusButton[j]
button1.addEventListener('click', decrmenetValue)
}
}
);
});
2023-05-11 03:32:37 +02:00
}
//<input class="input-group-field" type="number" name="quantity" value="1">
//var addItemButton = document.getElementsByClassName("input-group-field");
function showValue(event)
{
2023-05-24 22:15:21 +02:00
2023-05-11 03:32:37 +02:00
var shopItem = event.parentElement.parentElement.parentElement
2023-05-24 22:15:21 +02:00
2023-05-11 03:32:37 +02:00
var title = shopItem.getElementsByTagName('h3')[0].innerHTML
var getValue = localStorage.getItem(title) || 0;
shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
2023-05-24 22:15:21 +02:00
2023-05-11 03:32:37 +02:00
}
function incrmenetValue(event)
{
2023-05-24 22:15:21 +02:00
2023-05-11 03:32:37 +02:00
var buttony = event.target
var shopItem = buttony.parentElement.parentElement.parentElement.parentElement.parentElement
var title = shopItem.getElementsByTagName('h3')[0].innerHTML
var getValue= localStorage.getItem(title) || 0;
2023-05-24 22:15:21 +02:00
// var getValue = shopItem.getElementsByClassName('input-group-field')[0].value;
2023-05-11 03:32:37 +02:00
if(getValue < 10){
2023-05-24 22:15:21 +02:00
getValue++;
}
2023-05-11 03:32:37 +02:00
shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
localStorage.setItem(title, getValue)
}
function decrmenetValue(event)
2023-05-24 22:15:21 +02:00
{
2023-05-11 03:32:37 +02:00
var buttony = event.target
var shopItem = buttony.parentElement.parentElement.parentElement.parentElement.parentElement
var title = shopItem.getElementsByTagName('h3')[0].innerHTML
var getValue= localStorage.getItem(title) || 0;
2023-05-24 22:15:21 +02:00
if(getValue > 0){
getValue--;
}
2023-05-11 03:32:37 +02:00
shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
localStorage.setItem(title, getValue)
}