Click to See Complete Forum and Search --> : new problems with functions


David Harrison
04-28-2003, 01:08 PM
Can anyone tell me what is wrong with the function below, when I try to use the function (many different times in the same script) where d, m and y are sometimes used for different things it doesn't work. If I wanted to use it I would put something like:
if(a==2){dd(date,month,year);}
where date, month and year are specified just before I use the function.

function dd(d,m,y){while(d<1){
if(m==1 || m==2 || m==4 || m==6 || m==8 || m==9 || m==11){d+=31;}
else if(m==5 || m==7 || m==10 || m==12){d+=30;}
else if(m==3 && (y/4)==(Math.round(y/4))){d+=29;}
else{d+=28;}
m-=1;
if(m<1){m=12;y-=1;}}}

What I've had to do is to take out the d,m,y from the brackets and put this to run the function:
if(a==2){
d=date;m=month;y=year;
dd();
date=d;month=m;year=y;}
which does work but why doesn't the other method work.

If you would like to look at the full source (which I don't recommend because it's 10Kb) you'll find it at
(the add. in my signature) + /everything.js
and it has two accompanying sources at
+ /cjdump.js and + /djdump.js
which are just really big functions that contain a lot of jokes that I wanted in separate files.

I can't understand why it isn't working when I have other functions that have two different whatchamecallit's in the brackets that work fine.

Also on a less important note, if you go to this page on my site
http://www.geocities.com/prejudiced_against_everyone/pjpage.html?joketype=clean&pagenumber=8&pdate=03&pmonth=11&pyear=02&pjname=28/10/02%20-%2003/11/02
take a look at the source and almost at the end of the line in the second script tag you'll see that it runs a function dispjokes();, I wanted this to be set to run when the pagenumber==2 || pagenumber==8 but for some reason when I put this on the end of everything.js when everything has been declared it just doesn't work and funny things start to happen like, all of the script not working.

If you know the answers to either of these questions then please tell me.

Also, I've just noticed that when you click on the link to a page on my site above why is it that there are no jokes on the page even though the address you're being linked to was copied and pasted into the message window straight from the address bar.

SniperX
04-29-2003, 06:32 AM
We need more info to help u - perhaps u could post ur entire code listing...


OR
you could ensure that when u call dd(d,m,y) that it acually has the three parameters
e.g.
<input type=button value=' Click Me ' onClick="dd(10,01,2003);">


That might be the problem.

OR
you could tell use what u are using the function for..

Regards
MW

Charles
04-29-2003, 06:35 AM
What exactly are you trying to do with this function? JavaScript can do an awful lot of Date work with its native methods.

David Harrison
04-30-2003, 07:44 AM
I have a previous jokes page on my site and there are a series of links with dates on so that they can select a particular week (monday to sunday).
I start off with a particular date and take away the (day - 1) from it to find the date that monday was on, eg. this week
30-(3-1) = 28 which is the date that monday was on, but sometimes like for instance for tomorrow it will be a negative number eg.
1-(4-1) = -2 so I will run the function and it should give me the date 28, and it will change the month and if required, the year to make those correct as well.
Then I will take 6 off to find hte date sunday was on and run the function again etc.
Anyway I've uploaded my entire site for you to take a look at (I haven't used function dd(d,m,y), I've uploaded the working version).

Fang
04-30-2003, 10:04 AM
whatchamecallit's = arguments

In the first case you are passing (the arguments) a copy of the three variables. You never actually change them.

David Harrison
04-30-2003, 01:11 PM
What do you mean?