Kerrie Schmiechen (Military Nursing)

List of Contributed Questions (Sorted by Newest to Oldest)

No Question(s) Posted yet!

List of Contributed Answer(s) (Sorted by Newest to Oldest)

Answer # 1 #

For multiple checkboxes with same name:

let checkboxes = document.querySelectorAll('input[name="options"]:checked');checkboxes.forEach(cb => console.log(cb.value));
This iterates over all checked checkboxes.

Answer # 2 #

To get the value of a checked checkbox in JavaScript, use:

let checkbox = document.getElementById('myCheckbox');if (checkbox.checked) {    console.log(checkbox.value);}
This will print the value if the checkbox is checked.