Function not defined problem

N

Navaidstech

Hi all...

I'm new to Java programming. I've seen how finicky java is as far case
and space sensitivity sensitivity is concerned. However, I'm slowly
getting hang of it.
I came accross this weird problem that I just can't figure out. First
of all, here is a link to the script:

http://www.ve3gop.com/aprs/

Explorer seems to open it fine, however the Firefox is pretty fussy
about it. I have just installed Firebug and everytime I load up the
page in Firefox, it returns with the following error:

UpdateData is not defined
Repeatericon.iconAnchor = new GPoint(6, 20);

I checked and rechecked the code and this doesn't make any sense to
me.

Can anyone help?

thanks
Alex
 
G

Geoffrey Summerhayes

Hi all...

I'm new to Java programming. I've seen how finicky java is as far case
and space sensitivity sensitivity is concerned. However, I'm slowly
getting hang of it.

Javascript ain't Java. Trust this, eh?
I came accross this weird problem that I just can't figure out. First
of all, here is a link to the script:

http://www.ve3gop.com/aprs/

Explorer seems to open it fine, however the Firefox is pretty fussy
about it. I have just installed Firebug and everytime I load up the
page in Firefox, it returns with the following error:

UpdateData is not defined
Repeatericon.iconAnchor = new GPoint(6, 20);

I checked and rechecked the code and this doesn't make any sense to
me.

It's a timing issue, you're calling UpdateData
immediately before its definition. Move the call.
 
N

Navaidstech

Javascript ain't Java. Trust this, eh?

What now???!!! I've seen a few things over the past few days that
would make me pull my hair, but I didn't see this one coming. LOL.

It's a timing issue, you're calling UpdateData
immediately before its definition. Move the call.

You mean move the entire Repeater icon definition along with the
UpdateData call to somewhere else in the program so it's not too close
to the actual function?

thanks
ALex
 
G

Geoffrey Summerhayes

What now???!!! I've seen a few things over the past few days that
would make me pull my hair, but I didn't see this one coming. LOL.





You mean move the entire Repeater icon definition along with the
UpdateData call to somewhere else in the program so it's not too close
to the actual function?

You could, I generally put function definitions
in the head and leave the body for the immediate
script. But the basic problem is the parser seeing
the UpdateData call, and trying to execute it,
before it has read and created the function.

This is quick copy from your script:

<*snip*>

UpdateData(RepeaterLocation);

function UpdateData(FollowMarker) {

<*snip*>


Quick fix is just changing it to:

function UpdateData(FollowMarker) {
....
}

UpdateData(RepeaterLocation);
 
N

Navaidstech

Right you are Geoff...

I moved the repeater definition to end of the script and now it works
great.
I would have never thought this would make a difference because I
thought that once a function is called, the script will find it
somehow and execute it... not so, it seems.

Thanks for the suggestion of moving all the functions to the head...
this sure will alleviate a ton of headaches.

Thanks for your help Geoff...

Alex
 
R

RobG

What now???!!! I've seen a few things over the past few days that
would make me pull my hair, but I didn't see this one coming. LOL.

While that may fix the problem, it is not because the call is before
the declaration - that order is not important. It is more likely that
a parameter passed in the call has not been set or is undefined (which
is the error that Safari reports).

updateData is called with a parameter RepeaterLocation, and *that* is
not defined until the very end. The function was being called with an
undeclared parameter.
You mean move the entire Repeater icon definition along with the
UpdateData call to somewhere else in the program so it's not too close
to the actual function?

If your function expects to be passed a value, ensure that happens or
handle cases where it doesn't. You can read about Identifier
Resolution, Execution Contexts and Scope Chains here:

<URL: http://www.jibbering.com/faq/faq_notes/closures.html#clIRExSc >
 
R

RobG

It depends on the programming language... With PHP for example, you can put
the function literally anywhere and it will be found/executed, but alas
with Javascript, its top to bottom....

That is not correct. While resolution proceeds from top top bottom
(which I think all programming languages do), function and variable
declarations are resolved before any code is executed. Try:

x();
// As much code as you like
function x(){ alert('hi');}


Try the link in my reply to Navaidstech.
 
R

RobG

That is not correct. While resolution proceeds from top top bottom
(which I think all programming languages do), function and variable
declarations are resolved before any code is executed. Try:

x();
// As much code as you like
function x(){ alert('hi');}

Try the link in my reply to Navaidstech.

On reflection, Richard's article may be a bit much for some. The
bottom line is that for each script block, declarations are all
processed first, then execution begins. Here's a simple example:

<script type="text/javascript">

x('hi'); // Shows 'hi';

var a = 'hi from a';
x(a); // Shows 'hi from a'

x(b); // Shows 'undefined' since b is declared before
// execution but not assigned a value until later

x(z); // Script aborts, "Can't find z" because
// it hasn't been declared.

// x is declared down here
function x (y){ alert(y); }

var b = 'hi from b'; // b declared but not assigned a value
// until execution gets to this point

</script>
 
N

Navaidstech

While that may fix the problem, it is not because the call is before
the declaration - that order is not important. It is more likely that
a parameter passed in the call has not been set or is undefined (which
is the error that Safari reports).

Rob, is this what Safari reports now?
Prior to Geoff's reply the entire repeater icon creation and
definition of the RepeaterLocation variable took place BEFORE the
UpdateLocation function. Firefox was reporting problems with this and
refused to run, while IE6 took it and was pretty happy with it.
I have since moved this icon creation procedure to the end and now
both Firefox and Exploder are happy.
updateData is called with a parameter RepeaterLocation, and *that* is
not defined until the very end. The function was being called with an
undeclared parameter.
Again, I'm not sure if you are referring to the old code but as it is
now, I'm declaring the RepeaterLocation variable first followed by
call to the function and passing on the RepeaterLocation parameter.
If your function expects to be passed a value, ensure that happens or
handle cases where it doesn't. You can read about Identifier
Resolution, Execution Contexts and Scope Chains here:

<URL:http://www.jibbering.com/faq/faq_notes/closures.html#clIRExSc>

More stuff to learn...LOL!
THanks!

Alex
 
N

Navaidstech

That is not correct. While resolution proceeds from top top bottom
(which I think all programming languages do), function and variable
declarations are resolved before any code is executed. Try:

x();
// As much code as you like
function x(){ alert('hi');}

Try the link in my reply to Navaidstech.

This is the idea I had set up prior to moving the icon procedure to
the end.
As I mentioned in my previous reply, IE6 was happy while Firefox was
not...

Alex
 
R

RobG

Rob, is this what Safari reports now?

No, it now says "can't find variable postamble" (as does Firefox)
because you've inserted a script element beyond the closing html tag
that tries to call it. You must put script elements in the body or
head.

Your DOCTYPE is XHTML strict, so all browsers should completely ignore
the error, however if you serve the page as application/xml, IE won't
show anything at all. A check using the Live HTTP headers plugin for
Firefox shows you are serving it as text/HTML, so the DOCTYPE is
ignored and browsers are treating it as poorly coded HTML.
 
L

-Lost

RobG said:
Your DOCTYPE is XHTML strict, so all browsers should completely ignore
the error, however if you serve the page as application/xml, IE won't
show anything at all. A check using the Live HTTP headers plugin for
Firefox shows you are serving it as text/HTML, so the DOCTYPE is
ignored and browsers are treating it as poorly coded HTML.

Do you know offhand, if I create a website that is perfectly viewable in
Safari (Windows), can I safely assume that it will look the same in
Safari (Mac) or is that a pipe dream?

My next question, assuming it's a pipe dream will be would you mind
viewing a site of mine and taking a screenshot? (My Mac is
incapacitated at the moment, or I would check myself.)
 
R

RobG

Do you know offhand, if I create a website that is perfectly viewable in
Safari (Windows), can I safely assume that it will look the same in
Safari (Mac) or is that a pipe dream?

I don't know, but I would assume so (i.e. it will look the same, not
it's a pipe dream ;-) )

My next question, assuming it's a pipe dream will be would you mind
viewing a site of mine and taking a screenshot? (My Mac is
incapacitated at the moment, or I would check myself.)

Sure, either put the URL here or e-mail me.
 
L

-Lost

RobG said:
I don't know, but I would assume so (i.e. it will look the same, not
it's a pipe dream ;-) )
Great!


Sure, either put the URL here or e-mail me.

Thanks. E-mail sent.
 
N

Navaidstech

No, it now says "can't find variable postamble" (as does Firefox)
because you've inserted a script element beyond the closing html tag
that tries to call it. You must put script elements in the body or
head.

Yeah, I'm not sure how that sneaked in there. I thought I had it
deleted before.
It's gone now, anyway.
Your DOCTYPE is XHTML strict, so all browsers should completely ignore
the error, however if you serve the page as application/xml, IE won't
show anything at all. A check using the Live HTTP headers plugin for
Firefox shows you are serving it as text/HTML, so the DOCTYPE is
ignored and browsers are treating it as poorly coded HTML.

OK...this brings up a question: what is the difference between the
application/xml and text/html?
thanks
ALex
 
L

-Lost

Navaidstech said:
Yeah, I'm not sure how that sneaked in there. I thought I had it
deleted before.
It's gone now, anyway.


OK...this brings up a question: what is the difference between the
application/xml and text/html?
thanks

All files, regardless of what they may be should always be sent with the
correct MIME type so that your UA or browsing device can make the
smartest possible choice in regards to handling the file.

http://www.webstandards.org/learn/articles/askw3c/sep2003/
http://www.w3.org/2003/01/xhtml-mimetype/content-negotiation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,886
Members
47,419
Latest member
ArturoBres

Latest Threads

Top