I found something strange when working with onclick to call a function. Let's say I have an input of type checkbox(it can be almost any type of input), with a name attribute and an onclick attached to it, calling a function:
function myFunction() {
alert("Hello World");
}
<form action='' method='post'>
<input type='checkbox' name='myFunction' onclick="myFunction()">
</form>
You can see that when the name of the input and the name of the function are the same I get TypeError: myFunction is not a function
.
But when they are different the function call works well. I couldn't find any documentation about this anywhere. Can someone shed some light on this?
function myFunction() {
alert("Hello World");
}
<form action='' method='post'>
<input type='checkbox' name='testName' onclick="myFunction()">
</form>