-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincrdecr.html
94 lines (85 loc) · 1.97 KB
/
incrdecr.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo</title>
</head>
<body>
<!-- Add quantity button -->
<form>
<div class="value-button" id="decrease" onclick="decreaseValue()" value="Decrease Value">-</div>
<input type="number" id="number" value="0" />
<div class="value-button" id="increase" onclick="increaseValue()" value="Increase Value">+</div>
</form>
<style>
form {
width: 300px;
margin: 0 auto;
text-align: center;
padding-top: 50px;
}
.value-button {
display: inline-block;
border: 1px solid #ddd;
margin: 0px;
width: 40px;
height: 20px;
text-align: center;
vertical-align: middle;
padding: 11px 0;
background: #eee;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.value-button:hover {
cursor: pointer;
}
form #decrease {
margin-right: -4px;
border-radius: 8px 0 0 8px;
}
form #increase {
margin-left: -4px;
border-radius: 0 8px 8px 0;
}
form #input-wrap {
margin: 0px;
padding: 0px;
}
input#number {
text-align: center;
border: none;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
margin: 0px;
width: 40px;
height: 40px;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
</style>
<script>
function increaseValue() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('number').value = value;
}
function decreaseValue() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value < 1 ? value = 1 : '';
value--;
document.getElementById('number').value = value;
}
</script>
</body>
</html>