If you do a console.log(faul)
in the click handler, you'll see that faul
is a global reference to the input with the same name.
The cause is that for historic reasons, (most if not all) browsers pollute the scope that form elements' inline event handlers are run in by making any element with a name attribute available as a reference by that name. The same is true for any element with an id attribute, but in global scope, by the way (demonstrated below).
Adding the handler using addEventListener()
instead of an inline attribute will circumvent this issue (demonstrated below as well).
document.querySelector('form button').addEventListener('click', function() {
console.log('from addEventListener handler: ', faul);
});
<script>
function faul() { alert("faul"); }
</script>
<form>
<button onclick="console.log('from inline handler:', faul)">log faul</button>
<button onclick="console.log(faul2)">log faul2</button>
<input name="faul" required>
<div id="faul2"></div>
</form>