-
Notifications
You must be signed in to change notification settings - Fork 27k
/
enabled-disabled-shipping.html
128 lines (112 loc) · 3.35 KB
/
enabled-disabled-shipping.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>:enabled and :disabled demo — shipping form</title>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Josefin Sans', sans-serif;
margin: 20px auto;
max-width: 460px;
}
fieldset {
padding: 10px 30px 0;
margin-bottom: 20px;
}
legend {
color: white;
background: black;
padding: 5px 10px;
}
fieldset > div {
margin-bottom: 20px;
display: flex;
}
button, label, input[type="text"] {
display: block;
font-family: inherit;
font-size: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
width: 100%;
padding: 5px;
height: 30px;
}
input {
box-shadow: inset 1px 1px 3px #ccc;
border-radius: 5px;
}
input:hover, input:focus {
background-color: #eee;
}
input[type="text"]:disabled {
background: #eee;
border: 1px solid #ccc;
}
label:has(+ :disabled) {
color: #aaa;
}
button {
width: 60%;
margin: 0 auto;
}
</style>
</head>
<body>
<form>
<fieldset id="shipping">
<legend>Shipping address</legend>
<div>
<label for="name1">Name: </label>
<input id="name1" name="name1" type="text" required>
</div>
<div>
<label for="address1">Address: </label>
<input id="address1" name="address1" type="text" required>
</div>
<div>
<label for="pcode1">Zip/postal code: </label>
<input id="pcode1" name="pcode1" type="text" required>
</div>
</fieldset>
<fieldset id="billing">
<legend>Billing address</legend>
<div>
<label for="billing-checkbox">Same as shipping address:</label>
<input type="checkbox" id="billing-checkbox" checked>
</div>
<div>
<label for="name" class="billing-label">Name: </label>
<input id="name" name="name" type="text" disabled required>
</div>
<div>
<label for="address2" class="billing-label">Address: </label>
<input id="address2" name="address2" type="text" disabled required>
</div>
<div>
<label for="pcode2" class="billing-label">Zip/postal code: </label>
<input id="pcode2" name="pcode2" type="text" disabled required>
</div>
</fieldset>
<div><button>Submit</button></div>
</form>
<script>
// Wait for the page to finish loading
document.addEventListener('DOMContentLoaded', function () {
// Attach `change` event listener to checkbox
document.getElementById('billing-checkbox').addEventListener('change', toggleBilling);
}, false);
function toggleBilling() {
// Select the billing text fields
let billingItems = document.querySelectorAll('#billing input[type="text"]');
// Toggle the billing text fields
for (let i = 0; i < billingItems.length; i++) {
billingItems[i].disabled = !billingItems[i].disabled;
}
}
</script>
</body>
</html>