<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">
  </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 disabled-label">Name: </label>
          <input id="name" name="name" type="text" disabled required>
        </div>
        <div>
          <label for="address2" class="billing-label disabled-label">Address: </label>
          <input id="address2" name="address2" type="text" disabled required>
        </div>
        <div>
          <label for="pcode2" class="billing-label disabled-label">Zip/postal code: </label>
          <input id="pcode2" name="pcode2" type="text" disabled required>
        </div>
      </fieldset>

      <div><button>Submit</button></div>
    </form>

    <script src="script.js"></script>
</body>

</html>
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;
}

.disabled-label {
  color: #aaa;
}

button {
  width: 60%;
  margin: 0 auto;
}
// 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"]');
  // Select the billing text labels
  let billingLabels = document.querySelectorAll('.billing-label');

  // Toggle the billing text fields and labels
  for (let i = 0; i < billingItems.length; i++) {
    billingItems[i].disabled = !billingItems[i].disabled;

    if(billingLabels[i].getAttribute('class') === 'billing-label disabled-label') {
      billingLabels[i].setAttribute('class', 'billing-label');
    } else {
      billingLabels[i].setAttribute('class', 'billing-label disabled-label');
    }
  }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.