EN
JavaScript - oninput event for input checkbox element example
9 points
In this article, we would like to show you how to handle input event for input checkbox element in JavaScript.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<label>
5
<input type="checkbox" oninput="onInput(this)" /> Agreement
6
</label>
7
<script>
8
9
function onInput(element) {
10
console.log('Agreement changed to ' + element.checked + ' by oninput event.');
11
}
12
13
</script>
14
</body>
15
</html>
xxxxxxxxxx
1
2
<html>
3
<body>
4
<label>
5
<input id="agreement" type="checkbox" /> Agreement
6
</label>
7
<script>
8
9
var agreement = document.getElementById('agreement');
10
11
agreement.oninput = function(element) {
12
console.log('Agreement changed to ' + agreement.checked + ' by oninput event.');
13
};
14
15
</script>
16
</body>
17
</html>
xxxxxxxxxx
1
2
<html>
3
<body>
4
<label>
5
<input id="agreement" type="checkbox" /> Agreement
6
</label>
7
<script>
8
9
var agreement = document.getElementById('agreement');
10
11
agreement.addEventListener('input', function(element) {
12
console.log('Agreement changed to ' + agreement.checked + ' by input event.');
13
});
14
15
</script>
16
</body>
17
</html>