1

Please, look at the HTML form below:

<form>
  <input  name="tesla" id="tesla">
  <button type="button" onclick="tesla()">BUTTON</button>        
</form>

When I try to execute the function tesla() by clicking the button, I get the following error:

Uncaught TypeError: 
tesla is not a function at HTMLButtonElement.onclick 

(index.html:14)
onclick @ index.html:14

I get this error in two situations:

1 - If I set the function NAME equal to the input NAME
[name="tesla" AND onclick="tesla()"]

Or

2 - If I set the function NAME equal to the input ID
[id="tesla" AND onclick="tesla()"]

(In the example above, I used all three equal)
When I use different names, I get no errors.
Why is this happening??
This is a very simple piece of code, this should not be happening...

Obs. The function I tested with:

function tesla(){
  console.log("text");
}

0 Answers0