I have to create a function to show the number of characters typed in the textarea. I think the code is ok, but I get an undefined error. Can you tell me why? Thanks.
<html>
<head>
<style>
textarea {
width: 200px;
height: 130px
}
</style>
</head>
<body>
<textarea onkeypress="caractere()" name="numar"></textarea>
<p>Number of characters typed: <span></span></p>
<script>
function caractere() {
document.getElementsByTagName('span')[0].innerHTML = document.getElementsByName('numar')[0].length;
}
</script>