HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 4th, 2000, 12:49 PM
atarbaer atarbaer is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 17 atarbaer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am trying to validate that a 'First date' entered in a form comes before a 'last date,' and that both dates entered come before today's date. Respondents are allowed to leave the field blank (coded as 99, below) or answer "don't know" (coded as 88, below). Using the code below, I was able to confirm that the first entered date comes before the second entered date, but I am not able to confirm that either date come before today's date. Any suggestions would be greatly appreciated.

Thanks in advance,
Atar

------------------------------------

<script language="JavaScript">
<!-- Begin


function y2k(number) { return (number < 1000) ? number + 1900 : number;}


var today=new Date();
var now=Date.UTC(y2k(today.getYear()),today.getMonth(),today.getDate(),0,0,0);

function valid_date(firstdiary) {
var fintday1 = firstdiary.fintday1.options[firstdiary.fintday1.selectedIndex].value;
var fintmo1 = firstdiary.fintmo1.options[firstdiary.fintmo1.selectedIndex].value;
var fintyr1 = firstdiary.fintyr1.options[firstdiary.fintyr1.selectedIndex].value;
var lintday1 = firstdiary.lintday1.options[firstdiary.lintday1.selectedIndex].value;
var lintmo1 = firstdiary.lintmo1.options[firstdiary.lintmo1.selectedIndex].value;
var lintyr1 = firstdiary.lintyr1.options[firstdiary.lintyr1.selectedIndex].value;

startdate = new Date(fintyr1-0,fintmo1-1,fintday1-0);
enddate = new Date(lintyr1-0,lintmo1-1,lintday1-0);


if ((fintday1!=99) &&
(fintday1!=88) &&
(fintmo1!=99) &&
(fintmo1!=88) &&
(fintyr1!=99) &&
(fintyr1!=88)) {
starttime=Date.UTC(y2k(startdate.getYear()),startdate.getMonth(),startdate.getDate(),0,0,0);
}
else (starttime = 'missing');


if ((lintday1!=99) &&
(lintday1!=88) &&
(lintmo1!=99) &&
(lintmo1!=88) &&
(lintyr1!=99) &&
(lintyr1!=88)) {
endtime = Date.UTC(y2k(enddate.getYear()),enddate.getMonth(),enddate.getDate(),0,0,0);
}
else (endtime = 'missing');


if ((starttime > now) && (starttime!='missing')){
alert('First date cannot be in the future');
return false;
}

// the alert above doesn't work

else if ((starttime > endtime) && (endtime!='missing') && (starttime!='missing')){
alert('First date cannot be after last date');
return false;
}

// the alert above does work

else if ((endtime > now) && (endtime!='missing')){
alert('Last date cannot be in the future');
return false;
}

// the alert above doesn't work

else{
// valid
}

return true;
}

//-->
</script>

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > Validate that a date comes before today's date


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT