Re: This (Javascript) function has an onClick event that calls a function that calls This function
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Tue, 24 Oct 2006 01:07:18 -0500
Bob Richardson wrote:
In Delphi, my problem is solved with a Forward Declaration. Is there a similar solution in JavaScript. Yes, I know this is a Delphi group, but I don't know the JavaScript term for "Forward"!
It's a fairly common term. Most programmers should know what you're talking about.
Besides, you're not really looking for a forward declaration. You're looking for Javascript's way of resolving mutually dependent functions, whatever that may be. Delphi uses "forward" and prototypes. C++ uses prototypes. Java doesn't use anything.
The title says it all. The prevmon() function is listed afterward, since it calls fDrawCal().I'm sure you see the problem...
I see what you think is the problem. Does that problem actually occur when you run the code, though? Your fDrawCal function isn't *using* the prevmon function. As far as the parser is concerned, it shouldn't notice any function at all. Instead, fDrawCal is simply writing a text string into the document. It's not until that text string arrives in the document that the browser needs to know what "prevmon" is.
Presumably, you don't actually _call_ fDrawCal until after prevmon is already defined.
prevmon(), in the onClick event, is not defined prior to being mentioned in the onClick event. But what's the solution? Here's the structure that I have now:
function fDrawCal(iMonth, iYear) {
..
document.write('<a onClick="prevmon()" ................
..
etc.
..
}
function prevmon() {
iMonth = iMonth-1;
if (iMonth==0) {iYear=iYear-1; iMonth=12}
fDrawCal(iMonth, iYear); }
--
Rob
.
- References:
- Prev by Date: This (Javascript) function has an onClick event that calls a function that calls This function
- Next by Date: Re: This (Javascript) function has an onClick event that calls a function that calls This function
- Previous by thread: This (Javascript) function has an onClick event that calls a function that calls This function
- Next by thread: Re: This (Javascript) function has an onClick event that calls a function that calls This function
- Index(es):