Snippets Collections
const visibleCheckboxes = document.querySelectorAll('.checky')

visibleCheckboxes.forEach(checkbox => checkbox.addEventListener('change', () => {
let hiddenCheckbox = checkbox.nextElementSibling;
checkbox.checked ? hiddenCheckbox.value = 'Yes' : hiddenCheckbox.value = 'No';
}))

//html
<label>
  <input type="checkbox" class="checky" />
  <input type="text" value="no" /> Cats
</label>
<label>
  <input type="checkbox" class="checky" />
  <input type="text" value="no" /> Dogs
</label>
<label>
  <input type="checkbox" class="checky" />
  <input type="text" value="no" /> Fish
</label>
star

Sat Jun 12 2021 09:32:20 GMT+0000 (Coordinated Universal Time) https://codepen.io/hisamparker/pen/jOBepgP

#mongoose #javascript #html #form-data #checkboxes

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension