quantity
html & css
Archived 4 months ago
S
spanish0778
Verified
building a website selling goods. Would this be good for adding/decreasing the quantity of a product.
<div style="display: flex; align-items: center; gap: 7px;">
<button onclick="decreaseQty()">−</button>
<input type="number" id="quantity" value="1" min="1" style="width: 50px; text-align: center;" />
<button onclick="increaseQty()">+</button>
</div>
<script>
function increaseQty() {
let qty = document.getElementById("quantity");
qty.value = parseInt(qty.value) + 1;
}
function decreaseQty() {
let qty = document.getElementById("quantity");
if (parseInt(qty.value) > parseInt(qty.min)) {
qty.value = parseInt(qty.value) - 1;
}
}</script>
<div style="display: flex; align-items: center; gap: 7px;">
<button onclick="decreaseQty()">−</button>
<input type="number" id="quantity" value="1" min="1" style="width: 50px; text-align: center;" />
<button onclick="increaseQty()">+</button>
</div>
<script>
function increaseQty() {
let qty = document.getElementById("quantity");
qty.value = parseInt(qty.value) + 1;
}
function decreaseQty() {
let qty = document.getElementById("quantity");
if (parseInt(qty.value) > parseInt(qty.min)) {
qty.value = parseInt(qty.value) - 1;
}
}</script>

