wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes A Javascript function is said as Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "A Javascript function is said as "Not a function"" Watch "A Javascript function is said as "Not a function"" New topic
Author

A Javascript function is said as "Not a function"

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

When i am calling a javascript function , on Onclick of Button click , an error gets displayed on to Fire Bug console , displaying it as "Not a Function "
please find the scren shot attached .


Please solve this issue . thanks .



[Thumbnail for Post.jpeg]


Save India From Corruption - Anna Hazare.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60758
    
  65

In addition to using code tags, making sure that the code is properly formatted might get more people to look at it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If you're defining functions inside the script tags, then the script tag should not also have a src specified. According to W3C's recommendation for script in HTML 4.01...
The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.

But you can do both...



"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

<script type="text/javascript">
//define here
</script>


Thanks Marc , at first i followed this approach only , but later chnaged it (Just want to say that not working either ways)

making sure that the code is properly formatted might get more people to look at it.


If its a Java Code , i would have entered Ctrl + Shift + F on Eclipse IDE to format the code , is there any way or open source plugins to format JSP / HTML Pages to format the code ??

and anyway still the problem persists any help ??
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234



I found the error , its strange , but its fact :



Just Replaced the onclicks function name from myButton to myButtons , may be myButton is a reserved word .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60758
    
  65

No, it is not a reserved word.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Ravi Kiran Va wrote:... Just Replaced the onclicks function name from myButton to myButtons ...

Can't say without knowing what's in the js file. But if that's what fixed it, my guess is you've defined myButton as a global var.

For example, if you did something like this in your js file...

...and then tried to add...

...that would produce a "not a function" error (it does in Safari anyway). Changing the function name would put a bandage on the situation, but you would still have some messy code.

Again, just a guess.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Some browsers let you reference elements by their id

so instead of


you can do [and should never do]



So it is just a name collision.

Use namespaces in your code and you will not have these issues.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Javascript function is said as "Not a function"
 
Similar Threads
problem in simple calculator
Focus issue in IE
dojo and javascript DOM issue
Changing the text of a buton
Help needed with DOJO and JSP