Reputation: 107
I have a problem with an html page
here a simplified version of the page
<html>
<head>
<script type="text/javascript">
function maxLength()
{
console.log('maxLength');
}
</script>
</head>
<body>
<input type"text" onblur="maxLength()">
</body>
</html>
on onblur event I receive this error
Uncaught TypeError: maxLength is not a function
but if i call the function from console it works without errors and print 'maxLength'
Why?
Upvotes: 2
Views: 1213
Reputation: 351
If you rename the function to something else it should work fine for you. The explanation is aptly given with Alex already. Example:
<html>
<head>
<script type="text/javascript">
function maximumLength()
{
console.log('maxLength');
}
</script>
</head>
<body>
<input type"text" onblur="maximumLength()">
</body>
</html>
Upvotes: 0
Reputation: 490213
The code there runs in the context of the input
, which has defined maxLength
.
Better developer tools would make it clearer:
maxLength
is not a function atHTMLInputElement.onblur
Rename your function to something else or use a different way of attaching the event listener.
Upvotes: 4