Just in Chronicles

Life as a Voyage

Javascript Error: functionName() is not a function

Reference: In my Javascript I keep getting “submit is not a function”. What did I do?

Developers often meet a javascript error that says “functionName() is not a function”, even though functionName() is the actual function and coded correctly. That message usually comes up when functionName() is not defined.

How come does this happen? There is a secret. Shhhh~

<input
	type="button"
	id="btnCheck"
	name="btnCheck"
	onclick="javascript:btnCheck();" />

<input
	type="button"
	id="btnCheck"
	name="btnCheck"
	onclick="javascript:checkSomething();" />

As seen above, there are two button controls. ID, name and onclick attribute on the first control are the same as each other. While as, the name attribute on the second control, is different from the onclick attribute.

The first one will not work and the second one will work. This is the secret. When an HTML tag calls javascript, the function name must be different from the control’s ID and name; otherwise it displays the error “functionName() is not a function”.

This is pretty basic understanding of using javascript. But sometimes developers overlook the basic. Let’s back to basic! 🙂

Advertisements

Written by Justin Yoo

28/09/2009 at 06:31

Posted in For Web

Tagged with ,

2 Responses

Subscribe to comments with RSS.

  1. Thank you!
    That fixed a problem that I had been battling for a few hours this morning!

    What was odd with my problem is that is was working with everything named the same, then just suddenly stopped.

    Many thanks!

    Chris

    14/12/2009 at 01:10

    • No worries! I’m pleased at your comment that you eventually coped with your problem.

      Justin

      15/12/2009 at 10:22


Comments are closed.