473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Function is not defined (but it is)

I declared a function in a file called somefile.js as follows:

function foo() {
alert ("yippi!"); }

In HTML-file i'm importing it by adding:

onClick='foo()'

The somefile.js is imported correctly (according to my breakpoints in
FireBug SOME code in the file is reached). Despite of that, as i cause the
onClick-event to fire, i get the error message: "Function is not defined".
How can i debug it? As far i can see, it should work. :)

--
Regards
Konrad Viltersten
Jun 27 '08 #1
3 26097
K Viltersten wrote on 19 mei 2008 in comp.lang.javascript:
I declared a function in a file called somefile.js as follows:

function foo() {
alert ("yippi!"); }

In HTML-file i'm importing it by adding:

onClick='foo()'

The somefile.js is imported correctly (according to my breakpoints in
FireBug SOME code in the file is reached). Despite of that, as i cause
the onClick-event to fire, i get the error message: "Function is not
defined". How can i debug it? As far i can see, it should work. :)
You made an error somewhere in your code, but how can we say,
if you only describe your code?

Start temporarily importing the js file in your page code for testing.
Read the error descriptions [all of them] and the error lines.
Place breakpoints.
Try diferent browsers.

Etc, all the usual stuff.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #2
"K Viltersten" <tm**@viltersten.comschreef in bericht
news:op***************@lp028.pagero.local...
I declared a function in a file called somefile.js as follows:

function foo() {
alert ("yippi!"); }

In HTML-file i'm importing it by adding:

onClick='foo()'

The somefile.js is imported correctly (according to my breakpoints in
FireBug SOME code in the file is reached). Despite of that, as i cause the
onClick-event to fire, i get the error message: "Function is not defined".
How can i debug it? As far i can see, it should work. :)

Are you sure that the declaration of foo() is in the global scope and not
inside another function?
Tom
Jun 27 '08 #3
>I declared a function in a file called somefile.js as follows:
>>
function foo() {
alert ("yippi!"); }

In HTML-file i'm importing it by adding:

onClick='foo()'

The somefile.js is imported correctly (according to my breakpoints in
FireBug SOME code in the file is reached). Despite of that, as i cause
the
onClick-event to fire, i get the error message: "Function is not
defined".
How can i debug it? As far i can see, it should work. :)

Are you sure that the declaration of foo() is in the global scope and not
inside another function?
Well, i checked for that parentesis-wise a while ago, so yes, i was sure..
Then you got me thinking and i tried to move the function around, just for
the sake of testing. And guess what - it turns out that the function
definition needs to be at the top of the file, before any other code
(except for comments, blanks and other functions, i guess)! That's
extremely surprising!

I'd expect the function definition to be in global scope if it's declared
OUTSIDE of any {}-pair but apparently, it's not sufficient. Problems
solved. Thanks! You were right about being out of scope, even if it didn't
appear that way to me.

--
Regards
Konrad Viltersten
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
33
by: Pushkar Pradhan | last post by:
I'm using clock() to time parts of my code e.g. clk1 = clock(); /* code */ clk2 = clock(); /* calculate time in secs */ ...... clk1 = clock(); /* code */ clk2 = clock();
21
by: Stephen Biggs | last post by:
Given this code: void f(void){} int main(void){return (int)f+5;} Is there anything wrong with this in terms of the standards? Is this legal C code? One compiler I'm working with compiles this...
3
by: chreo | last post by:
I have user-defined function in MSSQL which returns Table (with 10 columns) (sorry for Polish names) CREATE FUNCTION PACZKI_Z_AKCJI (@AKCJA_ID int) RETURNS TABLE RETURN SELECT TOP 100...
13
by: Anthony de Almeida Lopes | last post by:
Hello, I am wondering why it is not possible to have a function-like macro like the following: #define __nothread(name) do { \ #ifdef _PTHREAD_H ...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
1
by: prads | last post by:
Hello, I found this waitbar functioning pgm in a forum which does the same work as a matlab waitbar. However this pgm has an error and i cudnot figure it out. Can anyone pls correct it. Thanks,...
11
by: aarklon | last post by:
Hi all, I have heard many discussions among my colleagues that main is a user defined function or not. arguments in favour:- 1) if it is built in function it must be defined in some header...
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.