473,574 Members | 5,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript">
<!--
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=m s[m]+d+"-"+h+".html" ;
}
//-->
</script>
</head>
<body onload="lp()"></body>
</html>

Thanks,
Ross Levis.
Jul 20 '05 #1
7 1637
Ross Levis wrote on 12 jul 2003 in comp.lang.javas cript:
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="JavaS cript">
<!--
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=m s[m]+d+"-"+h+".html" ;
}
//-->
</script>
</head>
<body onload="lp()"></body>
</html>


Please explain "not working", as this works:

<script language="JavaS cript">
<!--
// 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=m s[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.javas cript:
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**@stationpla ylist.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**@stationpl aylist.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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.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.javas cript:
JRS: In article <Fc************ *********@news. xtra.co.nz>, seen in
news:comp.lang. javascript, Ross Levis <ro**@stationpl aylist.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.javas cript:
"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
2366
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 help but say i was totally impressed. I needed an open source wikiblog/wikilog, whatever you wanna call it, basically a hybrid of a blog and a wiki. I...
10
3392
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 language="JavaScript"> function doWord(file) { if (navigator.userAgent.indexOf("MSIE")!=-1)
6
2016
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
13335
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 wrong????? Function x select case z
8
279
by: DJ | last post by:
What is wrong? #include <stdio.h> #define N 8 void order(int *p, int *q); int main(void)
10
3208
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
1869
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 element { int index; struct element *next;
1
1460
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 http://www.ebay.com google http://www.google.com yahoo http://www.yahoo.com However in the drop down list displayed value used ebay ...
9
2114
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
2227
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; i++){ for (k = 0; k < point3; k++){
0
7826
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7741
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8085
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5637
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5328
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3763
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2257
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.