0

I just want to understand this part. I renders well on w3schools but when I try to run it, value only shows undefined. thank you for your help.

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<input type="number" name="non" oninput="myFunction()">
<textarea id="demo"></textarea>
</body>
<script type="text/javascript">
    function myFunction() {
        var x = document.getElementsByTagName('non').value;
        document.getElementById('demo').innerHTML = "your value:" + x;
    }
</script>
</html>
  • Althought marked as a duplicate, it's notable, that `getElementsByTagName` collects elements by the ... well ... tag name, not by the name attribute. – Teemu Feb 02 '21 at 05:39
  • replace your function with this code it will work. ` function myFunction() { var x = document.getElementsByName("non")[0].value; document.getElementById('demo').value = x; }` – Shivansh Seth Feb 02 '21 at 05:47

0 Answers0