jeudi 31 décembre 2020

Why does an unchecked checkbox have a value of 'on'?

(Also replicated in JSfiddle)

Given an HTML checkbox:

<input type="checkbox">

The checkbox is displayed with no tick:

enter image description here

Logging the value of the element:

console.log(document.querySelector('input').value)

Logs on, even though the checkbox is unchecked.

Why is the value of the checkbox 'on', when the checkbox is unchecked?

How can I get the correct value?




Aucun commentaire:

Enregistrer un commentaire