[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [CF-Scripting] Syntax error
- To: "Richard Lovelock" <richcf@gmail.com>, "Javascript, CSS, XML,DHTML" <scripting@list.cfdeveloper.co.uk>
- Subject: RE: [CF-Scripting] Syntax error
- From: "Adrian Lynch" <contact@adrianlynch.co.uk>
- Date: Fri, 25 Feb 2005 15:58:13 -0000
- Cc:
- Importance: Normal
- In-reply-to: <91fbd97005022507537b85c2af@mail.gmail.com>
- List-archive: <http://list.cfdeveloper.co.uk/pipermail/scripting>
- List-help: <mailto:scripting-request@list.cfdeveloper.co.uk?subject=help>
- List-id: Javascript, CSS, XML, DHTML <scripting.list.cfdeveloper.co.uk>
- List-post: <mailto:scripting@list.cfdeveloper.co.uk>
- List-subscribe: <http://list.cfdeveloper.co.uk/mailman/listinfo/scripting>, <mailto:scripting-request@list.cfdeveloper.co.uk?subject=subscribe>
- List-unsubscribe: <http://list.cfdeveloper.co.uk/mailman/listinfo/scripting>, <mailto:scripting-request@list.cfdeveloper.co.uk?subject=unsubscribe>
- Reply-to: "Javascript, CSS, XML, DHTML" <scripting@list.cfdeveloper.co.uk>
Join up the = = so it has no space.
-----Original Message-----
From: scripting-bounces@list.cfdeveloper.co.uk
[mailto:scripting-bounces@list.cfdeveloper.co.uk]On Behalf Of Richard
Lovelock
Sent: 25 February 2005 15:54
To: scripting@list.cfdeveloper.co.uk
Subject: [CF-Scripting] Syntax error
>- see footer for list info
Hi
I am getting a syntax error on the following script on line 33, char
28 (if (testDate.getDate( ) = = day) {)
Could somebody give it the once over and let me know what is wrong
with it please (it is actually taken from an O'Reilly text and I have
eyed it correctly with the book a couple of times):
<script language="JavaScript">
function checkDate(fld) {
var mo, day, yr;
var entry = fld.value;
var reLong = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
var reShort = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{2}\b/;
var valid = (reLong.test(entry)) || (reShort.test(entry));
if (valid) {
var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
var delim1 = entry.indexOf(delimChar);
var delim2 = entry.lastIndexOf(delimChar);
mo = parseInt(entry.substring(0, delim1), 10);
day = parseInt(entry.substring(delim1+1, delim2), 10);
yr = parseInt(entry.substring(delim2+1), 10);
//handle 2 digit year
if (yr < 100) {
var today = new Date();
//get current century floor (e.g. 2000)
var currCent = parseInt(today.getFullYear() / 100) * 100;
//two digits up to this year + 15 expands to current century
var threshold = (today.getFullYear() + 15) - currCent;
if (yr > threshold) {
yr += currCent - 100;
} else {
yr += currCent;
}
}
var testDate = new Date(yr, mo-1, day);
if (testDate.getDate( ) = = day) {
if (testDate.getMonth() + 1 = = mo) {
if (testDate.getFullYear() = = yr) {
//fill field with database-friendly format
fld.value = mo + "/" + day + "/" + yr;
return true;
} else {
alert("There is a problem with the year entry.");
}
} else {
alert("There is a problem with the month entry.");
}
} else {
alert("There is a problem with the date entry");
}
} else {
alert("Incorrect date format. Enter as mm/dd/yyyy.");
}
return false;
}
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="dateIn"
onBlur="checkDate(document.myForm.dateIn.value)">
<br>
<input type="text" name="dateOut">
<br>
<input type="reset" name="Reset">
</form>
--
Richard Lovelock
_______________________________________________
For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- Support and list management provided by Russ Michaels -<
--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005