javascript problem
I am having trouble with a script i wrote I had a joke of the day on my site and had been updating it manually, but then i wrote a script to do it automatically for me which has a few problems i cant figure out. It only updates itself if ur comp is on at midnight and then if u restart ur comp it resets itself so the only way it will work now is if u have ur comp on 24/7 which most ppl don't. The script i used is as follows
var jokday = 0;
var joday = new Array("my jokes","went here","like this");
var dadate = new Date();
var the_hour = dadate.getHours();
if (the_hour == 0){jokday = jokday + 1};
var jday = "";
jday=joday[jokday];
where i wanted the joke to appear i put this script
document.writeln(jday)
so whats going on and how do i fix it??? plz help me
Suzanne posted this at 00:28 — 6th May 2004.
She has: 5,507 posts
Joined: Feb 2000
Your home computer is your server?
This seems like the sort of thing you'd want to use a) cookies and b) server-side programming for.
tomaine2002 posted this at 01:08 — 6th May 2004.
They have: 83 posts
Joined: Apr 2004
i am serving the files off of a server. Unfortunately I am pretty new to web site design and know nothign about sever-side programming or how i'd use a cookie to fix this.
pmj7 posted this at 21:41 — 7th May 2004.
He has: 234 posts
Joined: Nov 2002
I agree with Suzanne.
The script appears ok, I don't understand how you've come to the conclusions you've made. What exactly happens when you use the script?
Peter
Touchup image processing applet
Pixel Development Web Design, Photography
tomaine2002 posted this at 14:03 — 8th May 2004.
They have: 83 posts
Joined: Apr 2004
srry if i didn't explain it 2 well... here's whats going on: The script only adds one to the variable jokday if the viewers computer is on at midnight .... problem 2 is if the viewer restarts his/her computer then jokday is reset to 0
pmj7 posted this at 14:50 — 8th May 2004.
He has: 234 posts
Joined: Nov 2002
var firstDay = 8
var joday = new Array("my jokes","went here","like this");
var dadate = new Date();
var jokeIdx = dadate.getDay() - firstDay;
// etc for month and year
// check if jokeIdx in bounds, ie: not indexing too far into joday
var joke = joday[jokeIdx];
Alternatively, why not just randomly bring up a joke? http://www.irt.org has info on writing JavaScript.
Peter
Touchup image processing applet
Pixel Development Web Design, Photography
tomaine2002 posted this at 23:56 — 11th May 2004.
They have: 83 posts
Joined: Apr 2004
I already have a random joke thing on the page.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.