Is it a leap year? What about in 1900? Get your leap year facts straight with this leap year calculator. Just enter the year you are interested in and the script reports whether it is a leap year or not. Or, enter a range of years and JavaScript will display all the leap years in that range.
Add the below code to the <body> section of your page:
<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin function
checkYear(year){ return(((year
%4==0)&&(year
%100!=0))||(year
%400==0))?1:0;
} function
leap(form){ year =form.year.value; var
Check1 =parseFloat(year); for(var
i =0;
i <
year.length;
i++){ var
sLetterCheck1 =
year.substring(i,
i+1); if(sLetterCheck1
<"0"||
sLetterCheck1 >"9"){ alert("Enter
a valid year."); form.year.focus(); form.year.select(); return; }
} if(year
<1582){ form.result.value=""; alert("Year
must be greater than 1581."); form.year.focus(); form.year.select(); return;
} checkYear(year); if(!checkYear(year))form.result.value="not a leap year."; elseform.result.value="a leap year.";
} function
MakeArray(n){ if(n
<=0){ this.length=0; returnthis;
} this.length=
n; for(var
i =1;
i <=
n;
i++){ this[i]=0;
} returnthis;
} var
listArray =new
MakeArray(160); varindex=0; function
list(form){ startyear =form.startyear.value; endyear =form.endyear.value; var
Check1 =parseFloat(startyear); var
Check2 =parseFloat(endyear); for(var
i =0;
i <
startyear.length;
i++){ var
sLetterCheck1 =
startyear.substring(i,
i+1); if(sLetterCheck1
<"0"||
sLetterCheck1 >"9"){ alert("Enter
a valid start year."); form.startyear.focus(); form.startyear.select(); return; }
} for(var
i =0;
i <
endyear.length;
i++){ var
sLetterCheck2 =
endyear.substring(i,
i+1); if(sLetterCheck2
<"0"||
sLetterCheck2 >"9"){ alert("Enter
a valid end year."); form.endyear.focus(); form.endyear.select(); return; }
} if(startyear
<1582){ form.yearlist.value=""; alert("Start
year must be greater than 1581."); form.startyear.focus(); form.startyear.select(); return;
} elseif(endyear
<=
startyear){ form.yearlist.value=""; alert("End
year must be greater than start year."); form.endyear.focus(); form.endyear.select(); return;
} else{ index=0; for(var
i=startyear;
i <=endyear;
i++){ if(checkYear(i)){ listArray[index]=
i; index++; } }
} var
allYears; allYears =""; for(
i =0;
i <index;
i++){ allYears +=
listArray[i]+"\r"+"\n"; form.yearlist.value=
allYears; }
} // End --> </script> <form> Check For Leap Year:<br> Year:
<input
type=textname=yearsize=4>
is <inputtype=textname=resultsize=15> <br>
<br> <inputtype=buttonvalue="Check
Year"onClick="leap(this.form);"> <br> Leap Years Within A Range:<br> Start Year:<inputtype=textname=startyearsize=4><br> End year: <inputtype="text"name="endyear"size=4><br>
<br> <inputtype=buttonname=listyearsvalue="List
Years"onClick="list(this.form);"> <br> <textareaname=yearlistrows=10cols=11></textarea>
</form>