Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have the following piece of javas

Status
Not open for further replies.

jlawler

Programmer
Feb 26, 2003
14
IE
I have the following piece of javascript code which evaluates if the value passed into a form is a valid date or not. The code works fine in IE and Netscape 4.75, but it doesn't in Netscape 6.2.

What can I do to make my code compatible to all three browser versions?

<code>
isDate(document.forms[sForm].elements[&quot;qq_yyyy&quot;+sLife].value, document.forms[sForm].elements[&quot;qq_mm&quot;+sLife].value, document.forms[sForm].elements[&quot;qq_dd&quot;+sLife].value)
</code>

returns true when a valid date is passed in
returns false otherwise.

Any help is much appreciated

Thanks
jlawler
 
what kind of error are you getting?



=========================================================
while (!succeed) try();
-jeff
 
In Netscape 6.2 the javascript function does not return true. It does in Netscape 4.75 and IE. Maybe Netscape 6.2 is not backward compatible ?!?
 
isDate() is not a core js function...show us your code for it.



=========================================================
while (!succeed) try();
-jeff
 
I have no implementation for the function...here's the exact code...it just checks the date value entered in a form, it then checks that the year is between 1900 and te current year....

Are you sure &quot; isDate (year, month, day)&quot; is not a core js function ?

if ((isDate(document.forms[sForm].elements[&quot;qq_yyyy&quot;+sLife].value, document.forms[sForm].elements[&quot;qq_mm&quot;+sLife].value, document.forms[sForm].elements[&quot;qq_dd&quot;+sLife].value) != true)||(document.forms[sForm].elements[&quot;qq_yyyy&quot;+sLife].value < 1900)||(document.forms[sForm].elements[&quot;qq_yyyy&quot;+sLife].value > thisYear))
{
***** Do some stuff ***
return;
}
 
quite sure...try this out; you'll get the error &quot;Object expected&quot;:

<html>
<head>
<script type=&quot;text/javascript&quot;>
alert(isDate(&quot;02/02/1902&quot;));
</script>
</head>
<body>
</body>
</html>

your page must define &quot;isDate()&quot; or include it somewhere in order to use it...




=========================================================
while (!succeed) try();
-jeff
 
also try

alert(typeof(isDate));
alert(typeof(isNaN));
;-)
-pete

 
the funny thing is I went through this with someone awhile ago here and they all of the sudden insisted their function was fixed and all was fine and when the code was posted isDate() was still there. [curse]

I wonder ........ [hammer]

_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
wasnt me....

but youre right, it's not js function...I found an implementation in an included file...and managed to solve the problem...

Here's the existing code

function isDate (year, month, day)
{ if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

var intYear = parseInt(year);
var intMonth = parseInt(month);
var intDay = parseInt(day);

if (intDay > daysInMonth(intMonth)){alert(&quot;code falling over here&quot;); return false;}

if ((intMonth == 2) && (intDay > daysInFeb(intYear))){alert(&quot;day ret fal 3&quot;); return false;}

return true;
}

function makeArray(n) {
for (var i = 1; i <= n; i++) {
this = 0
}
return this
}

var days = makeArray(12);
days[1] = 31; days[2] = 29; days[3] = 31; days[4] = 30; days[5] = 31; days[6] = 30;
days[7] = 31; days[8] = 31; days[9] = 30; days[10] = 31; days[11] = 30; days[12] = 31;


I changed the isDate() function as follows

if (intDay > daysInMonth(intMonth))return false;}

and added the function

function daysInMonth(n) {
var val = 31;
if (n==4 || n==6 || n==9 || n==11) {val = 30}
if (n==2) {val = 29}

return parseInt(val);
}

I dont know why Netscape 6.2 was misbehaving, but it works now....Thanks a million for your time ....jlawler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top