473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

what's wrong with this...

I wrote some javascript code a couple of years ago to load a web page based
on the current date & time. I just modified it today to change the naming
format of the web pages and I can't get it to work at all. Even the old one
which was working (on Win98) is not working at all on my WinXP Pro. Has
some new requirement been introduced?

Can anyone see what's wrong with the following code. If it is 9am on July
12, it should load a web page named: Jul12-09.html, but it does nothing at
all.

<html>
<head>
<script language="JavaScript">
<!--
function lp() {
ms=new Array(11);
ms[0]="Jan";
ms[1]="Feb";
ms[2]="Mar";
ms[3]="Apr";
ms[4]="May";
ms[5]="Jun";
ms[6]="Jul";
ms[7]="Aug";
ms[8]="Sep";
ms[9]="Oct";
ms[10]="Nov";
ms[11]="Dec";
dt=new Date();
m=dt.getMonth();
d=dt.getDate();
d=(d<10)?"0"+d:d;
h=dt.getHours();
h=(h<10)?"0"+h:h;
location.href=ms[m]+d+"-"+h+".html";
}
//-->
</script>
</head>
<body onload="lp()"></body>
</html>

Thanks,
Ross Levis.
Jul 20 '05 #1
7 1627
Ross Levis wrote on 12 jul 2003 in comp.lang.javascript:
I wrote some javascript code a couple of years ago to load a web page
based on the current date & time. I just modified it today to change
the naming format of the web pages and I can't get it to work at all.
Even the old one which was working (on Win98) is not working at all on
my WinXP Pro. Has some new requirement been introduced?

Can anyone see what's wrong with the following code. If it is 9am on
July 12, it should load a web page named: Jul12-09.html, but it does
nothing at all.

<html>
<head>
<script language="JavaScript">
<!--
function lp() {
ms=new Array(11);
ms[0]="Jan";
ms[1]="Feb";
ms[2]="Mar";
ms[3]="Apr";
ms[4]="May";
ms[5]="Jun";
ms[6]="Jul";
ms[7]="Aug";
ms[8]="Sep";
ms[9]="Oct";
ms[10]="Nov";
ms[11]="Dec";
dt=new Date();
m=dt.getMonth();
d=dt.getDate();
d=(d<10)?"0"+d:d;
h=dt.getHours();
h=(h<10)?"0"+h:h;
location.href=ms[m]+d+"-"+h+".html";
}
//-->
</script>
</head>
<body onload="lp()"></body>
</html>


Please explain "not working", as this works:

<script language="JavaScript">
<!--
// function lp() {
ms=new Array(11);
ms[0]="Jan";
ms[1]="Feb";
ms[2]="Mar";
ms[3]="Apr";
ms[4]="May";
ms[5]="Jun";
ms[6]="Jul";
ms[7]="Aug";
ms[8]="Sep";
ms[9]="Oct";
ms[10]="Nov";
ms[11]="Dec";
dt=new Date();
m=dt.getMonth();
d=dt.getDate();
d=(d<10)?"0"+d:d;
h=dt.getHours();
h=(h<10)?"0"+h:h;
// location.href=ms[m]+d+"-"+h+".html";
alert(ms[m]+d+"-"+h+".html");
// }
//-->
</script>

Perhaps your relative location is not leading to a file.

Local time here still gives:

Jul12-08.html

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
DU wrote on 12 jul 2003 in comp.lang.javascript:
ms=new Array(11);
Your script is requesting to create an array for 11 items, not 12.


Good for you, I didn't see that!
I recommend explicitly declaring each local variables
with the var keyword.


why ?
DU wrote:
Your script is requesting to create an array for 11 items, not 12.

I wondered about that. I tried 12 but no difference.


Test it again in December ;-)

btw: cann't you do this with serverside redirecting ?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3
In article <Fc*********************@news.xtra.co.nz>,
ro**@stationplaylist.dot.com says...
I wrote some javascript code a couple of years ago to load a web page based
on the current date & time. I just modified it today to change the naming
format of the web pages and I can't get it to work at all. Even the old one
which was working (on Win98) is not working at all on my WinXP Pro. Has
some new requirement been introduced?

Can anyone see what's wrong with the following code. If it is 9am on July
12, it should load a web page named: Jul12-09.html, but it does nothing at
all.


Works for me in IE6 and Moz1.something under XP Pro.

--
Hywel Never knowingly understood
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php
Jul 20 '05 #4
DU
Ross Levis wrote:
DU wrote:
Your script is requesting to create an array for 11 items, not 12.

I wondered about that. I tried 12 but no difference.

I recommend explicitly declaring each local variables with the var


keyword.

OK, but that should not stop it working should it?


It's just good and sound coding techniques. Same thing with using a
doctype declaration and making sure that the markup is valid to begin
with. FYI, even MSDN kinda suggest this when script problems appear.
Ross.


When you say "not working", please be specific, give details, describe,
paste the javascript console error message(s) if any, define the
browsers and browser versions that do not work, etc... As far as I can
see, this should work and I tested the code (not the same as given) and
it worked in MSIE 6 for Windows (standards compliant rendering mode) and
with NS 7.1.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #5
JRS: In article <Fc*********************@news.xtra.co.nz>, seen in
news:comp.lang.javascript, Ross Levis <ro**@stationplaylist.dot.com>
posted at Sat, 12 Jul 2003 17:41:56 :-
ms=new Array(11);
ms[0]="Jan";
ms[1]="Feb";
ms[2]="Mar";
ms[3]="Apr";
ms[4]="May";
ms[5]="Jun";
ms[6]="Jul";
ms[7]="Aug";
ms[8]="Sep";
ms[9]="Oct";
ms[10]="Nov";
ms[11]="Dec";


Your code fails appropriately in my system, complaining about the
absence of the page Jul12-18.html.

ms = ["Jan", "Feb", ..., "Dec"] // saves space, and counting.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #6
Dr John Stockton wrote on 12 jul 2003 in comp.lang.javascript:
JRS: In article <Fc*********************@news.xtra.co.nz>, seen in
news:comp.lang.javascript, Ross Levis <ro**@stationplaylist.dot.com>
posted at Sat, 12 Jul 2003 17:41:56 :-
ms=new Array(11);
ms[0]="Jan";
ms[1]="Feb";
ms[2]="Mar";
ms[3]="Apr";
ms[4]="May";
ms[5]="Jun";
ms[6]="Jul";
ms[7]="Aug";
ms[8]="Sep";
ms[9]="Oct";
ms[10]="Nov";
ms[11]="Dec";


Your code fails appropriately in my system, complaining about the
absence of the page Jul12-18.html.

ms = ["Jan", "Feb", ..., "Dec"] // saves space, and counting.


an alternate way saves on counting only:

ms=new Array(12);
// 12 !!
n = 0;
ms[n++]="Jan";
ms[n++]="Feb";
ms[n++]="Mar";
ms[n++]="Apr";
ms[n++]="May";
ms[n++]="Jun";
// these rows can easily be sorted alphabetically in an editor,
// not usefull in this months case of course.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #7
Lasse Reichstein Nielsen wrote on 13 jul 2003 in comp.lang.javascript:
"Evertjan." writes:
Test it again in December ;-)


It won't matter. Javascript arrays can have their lengths changed
dynamically, so when it executes
ms[11]="Dec";


I know that. It was partly ment as a joke. ";-)"

But also it is good practice to test such things out
for instance by temporariliy insertion:

.......
dt=new Date();
m=dt.getMonth();
m = 11; // this is the extra test line
.......
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike Henley | last post by:
I first came across rebol a while ago; it seemed interesting but then i was put off by its proprietary nature, although the core of the language is a free download. Recently however, i can't...
10
by: Greener | last post by:
Hi, I need help badly. Can you do client-side programming instead of server-side to capture the Browser type info? If this is the case, what's wrong with the following? <script...
6
by: Rtritell | last post by:
Please can you find out what's wrong, fix the script and tell me what was wrong. Im just beginning <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
8
by: DJ | last post by:
What is wrong? #include <stdio.h> #define N 8 void order(int *p, int *q); int main(void)
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
12
by: questions? | last post by:
I am testing a problem with linked list. I just do a lot of times: create a list, then free it. ############################################# # include <stdio.h> # include <stdlib.h> struct...
1
by: GS | last post by:
I got a combobox box that I load at load time. the Item and vales ended up in reverse order of each other, what went wrong? the database table has the following row code value ebay ...
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
2
by: mingke | last post by:
Hi... So I have problem with my if condition..I don't know what's wrong but it keeps resulting the wrong answer.... So here's the part of my code I have problem with: for (i=0; i<size2;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.