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()"
Classic bug! You need to provide a function, rather than actually calling the function. The key here is
onClick="App.validate()"
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
onClick="App.validate"
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:
<script>
console.log('App.validate: ',App.validate)
console.log("App.validate('yourname')", App.validate('yourname'))
</script>
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!