This function has an onClick event that calls a function that calls This function

B

Bob

The title says it all. The nextmon() and prevmon() functions are listed
afterward, since they call fDrawCal().I'm sure you see the
problem...prevmon() 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) {
var myMonth;
myMonth = fBuildCal(iYear, iMonth);
document.write('<table id="calendar" cellspacing="0" cellpadding="0"
summary="One month calendar">');
document.write('<caption><a onClick="prevmon()" title="previous month"
class="nav">&laquo;&nbsp;</a>'+ThisMonth+' '+iYear+'<a onClick"nextmon"
title="next month" class="nav">&nbsp;&raquo;</a></caption>');
document.write(' <tr>');
...
etc.
...
}

function nextmon() {
iMonth = iMonth+1;
if (iMonth==13) {iYear=iYear+1; iMonth=1}
fDrawCal(iMonth, iYear);
}

function prevmon() {
iMonth = iMonth-1;
if (iMonth==0) {iYear=iYear-1; iMonth=12}
fDrawCal(iMonth, iYear);
}
 
R

RobG

Bob said:
The title says it all.

No it doesn't.
The nextmon() and prevmon() functions are listed
afterward, since they call fDrawCal().I'm sure you see the
problem...prevmon() is not defined prior to being mentioned in the
onClick event.

That isn't the problem (at least for what you have posted). Your call
to document.write will completely erase the content of the document,
the script that is in the page no longer exists when the new page is
written.

But what's the solution?

Do not use document.write() to build your calendar, use a in-page popup
(like thousands of calendar pop-ups already do).

Matt Kruse has a bunch of them here:

<URL: http://www.mattkruse.com/javascript/calendarpopup/ >
 
B

Bob

Do not use document.write() to build your calendar, use a in-page popup
(like thousands of calendar pop-ups already do).

Matt Kruse has a bunch of them here:

<URL: http://www.mattkruse.com/javascript/calendarpopup/ >

I'm not trying to select a date. CSS controls the position of the
calendar. I was hoping to have the onClick event create another
calendar...on top of the initial calendar, on the page - not as a pop
up.

In Pascal/Delphi there is a Forward declaration that handles this type
of organization.

var Imon = 1;
function Foo; forward;

function Bar(Imon) {
if (Imon <> 12) {Foo();}
}

function Foo() {
Imon = Imon+1;
Bar(Imon)
}

This is somewhat like recursion.

I was hoping that there is some way in JavaScript to code something
like this structure.
 
R

RobG

Bob said:
I'm not trying to select a date. CSS controls the position of the
calendar. I was hoping to have the onClick event create another
calendar...on top of the initial calendar, on the page - not as a pop
up.

Then just put it in the page inside a div or whatever. Your
fundamental problem is using document.write() after the page has
finished loading - it completely replaces the current content of the
page.

In Pascal/Delphi there is a Forward declaration that handles this type
of organization.

It has been over 15 years since I had anything to do with Pascal and
have never used any version of Delphi. There is no point in explaining
javascript in terms of code from some other language unless you know
that I know that language.

[...]
This is somewhat like recursion.

I can't see how it has any relevance to the problem at hand.

One of Matt's functions writes a calendar into a div element (the one
labelled "Default calendar using the DIV-style display"). He uses it as
a pop-up, to convert it to a stock page element, change the style stuff
in regard to position and display attributes and there you have it.
 
N

news

Bob said:
I'm not trying to select a date. CSS controls the position of the
calendar. I was hoping to have the onClick event create another
calendar...on top of the initial calendar, on the page - not as a pop
up.

In Pascal/Delphi there is a Forward declaration that handles this type
of organization.

var Imon = 1;
function Foo; forward;

function Bar(Imon) {
if (Imon <> 12) {Foo();}
}

function Foo() {
Imon = Imon+1;
Bar(Imon)
}

I was hoping that there is some way in JavaScript to code something
like this structure.

You are misunderstanding the problem - it is not that your code is
refering to a function that has not yet been defined (javascript
couldn't care less), it is that document.write replaces the content of
the current document with the string you send it. Trying to apply
language concepts from Pascal to Javascript is only going to hurt you,
as it is here.

You are wiping out your code completely when you use document.write, so
the function your onclick handler calls nolonger exists. This is what
the previous poster was trying to explain to you.

The solution is not to use document.write (and thus create a new
document) as was already pointed out, but to replace the calendar
within the current document. RobG has already given you pointers on how
to do this.
 
B

Bob

You are misunderstanding the problem - it is not that your code is
refering to a function that has not yet been defined (javascript
couldn't care less), it is that document.write replaces the content of
the current document with the string you send it. Trying to apply
language concepts from Pascal to Javascript is only going to hurt you,
as it is here.

Thanks Rob and N.. I now understand the real problem - the most
important part to solving any problem.
 

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
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top