I have this error > App.validate is not a function at HTMLInputElement.onclick

The code is here :

i get error in the last ( >) input type="submit" name="submit" onclick="App.validate()"

1 Answer 1


Classic bug! You need to provide a function, rather than actually calling the function. The key here is


By adding the () after validate, your code is instantly calling validate when the page loads -- the return value of App.validate() is what's actually being set as onClick. If you change it to


then you'll be passing the function itself rather than its return value.

Edit: That said, you should double check that your function actually exists. Try adding a script tag which calls the function with some sample input and then logs it:

  console.log('App.validate: ',App.validate)
  console.log("App.validate('yourname')", App.validate('yourname'))

If the first line prints out your function and the second line works correctly, then you ought to be good to go. If not, then the function doesn't exist where you think it does and now you know where to look next in your debugging process!

Not the answer you're looking for? Browse other questions tagged or ask your own question.