79092304

Date: 2024-10-16 02:50:11
Score: 0.5
Natty:
Report link
    <html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Check All Example</title>
</head>
<body>

  <select id="selectOption">
    <option value="default">Select an option</option>
    <option value="completed">Completed</option>
  </select>

  <div>
    <input type="checkbox" id="check1"> Item 1<br>
    <input type="checkbox" id="check2"> Item 2<br>
    <input type="checkbox" id="check3"> Item 3<br>
  </div>

  <script>
    document.getElementById('selectOption').addEventListener('change', function() {
      const checkboxes = document.querySelectorAll('input[type="checkbox"]');
      if (this.value === 'completed') {
        checkboxes.forEach(checkbox => checkbox.checked = true);
      }
    });
  </script>

</body>
</html>

just use this code for example. easy, simple and yet understandable

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Efan