Assimalyst wrote:
> Hi,
>
> I have a working script that converts a dd/mm/yyyy text box date entry
> to yyyy/mm/dd and compares it to the current date, giving an error
> through an asp.net custom validator, it is as follows:
>
> function doDateCheckNow(source, args)
> {
> var oDate = document.getElementById(source.controltovalidate); //
> dd/mm/yyyy
> var arrDate = oDate.value.split("/");
> var useDate = new Date(arrDate[2], arrDate[1]-1, arrDate[0]); //
> yyyy/mm/dd
> var today = new Date();
>
> if (useDate <= today)
> {
> args.IsValid = true;
> }
> else
> {
> args.IsValid = false;
> }
> }
>
> I have then attempted to use an adapted version of this to compare a
> date entered into a text box (dodTxtBx) with the text loaded into an
> asp.net label (dobLbl):
>
> function doDateCheckDod(dodTxtBx, dobLbl, args)
> {
> // Convert DOD to javascript date format
> var oDodDate = dodTxtBx; // dd/mm/yyyy
> var arrDodDate = oDodDate.value.split("/");
> var useDodDate = new Date(arrDodDate[2], arrDodDate[1],
> arrDodDate[0]); // yyyy/mm/dd
>
> // Convert DOB to javascript date format
> var oDobDate = dobLbl; // dd/mm/yyyy
> var arrDobDate = oDobDate.value.split("/");
> var useDobDate = new Date(arrDobDate[2], arrDobDate[1],
> arrDobDate[0]); // yyyy/mm/dd
>
> if (useDobDate < useDodDate)
> {
> args.IsValid = true;
> }
> else
> {
> args.IsValid = false;
> }
> }
>
> But this creates errors on the page when it runs and always fails the
> custom validator.
>
> Any ideas why?
>
> Many Thanks
Your function works fine for me when called correctly: (IE6 & Firefox
1.5)
<input type="text" id="timetest" onblur="doDateCheckNow(this);">
function doDateCheckNow(source) {
var oDate = source; //dd/mm/yyyy
var arrDate = oDate.value.split("/");
var useDate = new Date(arrDate[2], arrDate[1]-1, arrDate[0]);
//yyyy/mm/dd
var today = new Date();
if (useDate <= today)
{
alert("true");
}
else
{
alert("false");
}
}
How are you calling your function? Try putting some alerts after each
variable is set/changes, to make sure your getting the text data from
your fields.
I don't know that this has anything to do with ASP...
- JS
Received on Mon May 1 05:25:30 2006