I am trying to create a web server that has multiple buttons that control the quantity (plus and minus). If I have 3 sets of plus buttons, minus buttons and text, it should not interfere with each other when I press on a certain set. How do I achieve this?
The code I wrote is:
var count=0;
var quantity = document.getElementById("quantity");
function plus(){
count++;
quantity.value = count;
}
function minus(){
if (count > 0) {
count--;
quantity.value = count;
}
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #f1f1f1;
max-width: 200px;
}
.row:after {
content: "";
display: table;
clear: both;
}
.row {margin: 0 -5px;}
.column {
float: left;
width: 15%;
padding: 0 10px;
}
@media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 20px;
}
}
<!DOCTYPE html>
<html lang="en" >
<head>
<title>My Page</title>
<meta charset="utf-8">
</head>
<body>
<div class="row">
<div class="column">
<div class="card">
<p><b>Item 1</b></p>
<p><input type='button' value='-' id="qtyminus" onclick="minus()"/>
<input type='text' id='quantity' value='0' style="width: 40px;" />
<input type='button' value='+' id="qtyplus" onclick="plus()"/></p>
</div>
</div>
<div class="column">
<div class="card">
<p><b>Item 2</b></p>
<p><input type='button' value='-' id="qtyminus" onclick="minus()"/>
<input type='text' id='quantity' value='0' style="width: 40px;" />
<input type='button' value='+' id="qtyplus" onclick="plus()"/></p>
</div>
</div>
<div class="column">
<div class="card">
<p><b>Item 3</b></p>
<p><input type='button' value='-' id="qtyminus" onclick="minus()"/>
<input type='text' id='quantity' value='0' style="width: 40px;" />
<input type='button' value='+' id="qtyplus" onclick="plus()"/></p>
</div>
</div>
</div>
</body>
</html>