Get value from form checkboxes
Sat Jun 12 2021 09:32:20 GMT+0000 (Coordinated Universal Time)
Saved by
@hisam
#mongoose
#javascript
#html
#form-data
#checkboxes
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>
content_copyCOPY
Getting values from form checkboxes that can be easily parsed by mongoose / mongodb
https://codepen.io/hisamparker/pen/jOBepgP
Comments