FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > General Coding/Development
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 11-14-2001, 01:13 AM   Postid: 56241
rick-k
Site Owner

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Sep 2000
Location: Ottawa, IL 61350
Posts: 22
Calendar JavaScript won't work in Netscape


I have a JavaScript day-of-the-week finder at
http://www.koshko.com/calendar/day-of-week-js.html

It works perfectly in Internet Explorer 5 and K-Meleon.
I'm stumped over why it won't work in Netscape Communicator 4.07. The problem seems to be Netscape won't treat the form input as a number instead of a string, so it tries to concatenate the variables for month and date. I've tried some variations and Netscape insists "e is undefined". Other variations come back with NaN. And others determine that every day is Sunday.

Maybe I just need a newer Netscape?

My apologies if this code doesn't post correctly but just in case it's not convenient to view the source, here goes.

function lookup(){
d=parseFloat(document.form1.date.value); // read date from form
m=parseFloat(document.form1.month.value); // read month value from form
y=parseFloat(document.form1.year.value); // read year from form
l=0; // default no leap year
g=(y%100); // last two digits of year
k=g%4; // remainder of last two digits of year divided by four
h=(g-k)/4; // last two digits of year divided by four dropping the fraction
c=((y-g)/100)%4; // remainder of century divided by four
p=y%100; // if year is divisible by 100 answer is 0
q=y%400; // if year is divisible by 400 answer is 0
if (m==0 && k==0) {l=1};
if (m==3 && k==0) {l=1};
if (m==0 && p==0) {l=0};
if (m==3 && p==0) {l=0};
if (m==0 && q==0) {l=1};
if (m==3 && q==0) {l=1};
z = d+m+g+h+6-2*c-l;
b = z%7;
if (b==0) {e="Sunday"};
if (b==1) {e="Monday"};
if (b==2) {e="Tuesday"};
if (b==3) {e="Wednesday"};
if (b==4) {e="Thursday"};
if (b==5) {e="Friday"};
if (b==6) {e="Saturday"};
document.form1.answer.value=e
}



Thanks in advance for all insight.

Rick Koshko
rick-k is offline   Reply With Quote
Old 11-14-2001, 02:22 AM   Postid: 56244
MinorMan
Visitor

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Feb 2001
Location: Gaithersburg, MD USA
Posts: 21
Haven't looked at the script, but I can tell you it does not work in Netscape 4.79 (Mac), either. However, it works fine in Mozilla 0.9.5.

John
MinorMan is offline   Reply With Quote
Old 11-21-2001, 09:34 PM   Postid: 56496
jadero
Visitor

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Nov 2001
Location: Saskatoon, SK, Canada
Posts: 14
General fix to prevent concatenation when adding

One of the problems with using the "+" operator for both addition (math) and concatenation (joining strings) is that 'weakly' typed variables (i.e. the variable has not been defined as being an integer, string, etc.) sometimes cause problems. One trick is to multiply each variable by 1, thus forcing the issue. Just so you know, I often run into this problem in various versions of IE as well. Sometimes it feels like I'm at the roulette table

a="2";
b="3";

c=a+b; //resolves to "23"
d=a*1 + b*1; //resolves to 5

a=a*1;
b=b*1;

e=a+b; //this should also resolve to 5
jadero is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 03:51 AM.


Running on vBulletin®
Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2013 FutureQuest, Inc.
FutureQuest, Inc.