JavaScript-from-Beginner-to.../Chapter 10/ex8 Input Number checker
2021-11-24 20:46:13 +05:30

29 lines
769 B
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html>
<head>
<title>JS Tester</title>
</head>
<body>
<div class="output"></div>
    <input type="text" name="myNum1">
    <input type="text" name="myNum2">
<script>
const eles = document.querySelectorAll("input");
const output = document.querySelector(".output");
eles.forEach(el => {
el.addEventListener("keydown", (e) => {
if (!isNaN(e.key)) {
output.textContent += e.key;
}
})
el.addEventListener("keydown", (e) => {
console.log(e.key);
})
el.addEventListener("paste", (e) => {
console.log('pasted');
})
})
</script>
</body>
</html>