Coding Global Background
Coding Global

quantity

html & css
Archived 3 months ago
2 messages
0 members
4 months ago
S
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>

quantity

Replies (2)