Comments in my javascripts 2
With the help of some good people from this community I've (or they) made 6 javascripts for me.
I'm in an emergency situation now I have to comment those codes.
I could have done it by myself but.....I can't.....
So if someone can help me please fell free!!!!
And here comes the 2nd one!
<html>
<head>
<title>Date Validation Test</title>
<link href="css.css" rel="stylesheet">
<style type="text/css">
<!--
.skicka_knapp {
background-color: #FFFF66;
border: #996633; border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 2px;
border-left-width: 2px}
p{
font-family: Verdana;
font-size:12px;
}
.form{
position:absolute;
left:150px;
top:200px;
}
.tit{
font-family:verdana;
font-size:10pt;
position:absolute;
left:150px;
top:170px;
}
</style>
<script language="javascript" type="text/javascript">
// this is the function to call from a button or event handler
function Validate()
{
// construct today's date without the time element
var dtTemp = new Date();
var dtToday = new Date(dtTemp.getFullYear(), dtTemp.getMonth(), dtTemp.getDate());
// check the date is OK
// CHANGE frmTest.txtDate TO YOUR FORM AND FIELD NAMES
if ( CheckValidDate(document.frmTest.txtDate.value, dtToday, null) )
{
// action if date OK
alert("date OK");
}
else
{
// action if check failed
alert("bad date");
}
}
// function to check dates
// if MinDate or MaxDate not required just pass null there
function CheckValidDate(sValueToTest, dtMinDate, dtMaxDate)
{
var cYEAR = 2, cMONTH = 1, cDAY = 0; // ### change these for other date formats
var bOK = true;
// attempt to convert to a date (assume dd/mm/yyyy format)
var dtValueToTest;
var aDate;
try
{
// ### change this for other date formats ###
aDate = sValueToTest.split("\/");
dtValueToTest = new Date(aDate[cYEAR], aDate[cMONTH] - 1, aDate[cDAY]);
if ( isNaN(dtValueToTest) )
{
bOK = false;
}
}
catch (e)
{
bOK = false;
}
// if the date conversion succeeded, check its the actual date that was input
// (e.g. it will accept 31/2/2003 but will change it to 3/3/2003)
if (bOK)
{
// is it the same year?
if (aDate[cYEAR] != dtValueToTest.getFullYear())
bOK = false;
// is it the same month?
if (aDate[cMONTH] != 1 + dtValueToTest.getMonth())
bOK = false;
// is it the same day?
if (aDate[cDAY] != dtValueToTest.getDate())
bOK = false;
}
// min value test
if (bOK && dtMinDate)
{
if (dtValueToTest < dtMinDate)
{
bOK = false;
}
}
// max value test
if (bOK && dtMaxDate)
{
if (dtValueToTest > dtMaxDate)
{
bOK = false;
}
}
return (bOK);
}
</script>
</head>
<body bgcolor="#FF9966" >
<div class="back"><a href="links.html">Tillbaka</a></div>
<div class="tit">Please type today's date</div>
<div class="form">
<form action="date2.html" method="POST" id="frmTest" name="frmTest">
<input type="text" id="txtDate" name="txtDate" class="skicka_knapp">
<input type="button" value="Validate" onclick="Validate();" class="skicka_knapp">
</form>
<p>Use this format :<br/>dd/mm/yyyy</p>
</div>
</body>
</html>
A big thanxs to all of you who helped me a lot!!!!
Thanxs!!!!!!
|