I have a form where the user can select a date using a series of dropdowns for Month, Day, Year. Upon selecting them all I want to test it to make sure that the date selected is not today’s date, nor a weekend date, if so, I want to show them an alert and return them to the form to make an adjustment.
The code below is working fine for the weekend test, and when I use the alert to show me what values are being created I see that both tripDate and todaysDate SHOW me the same values, IF test is not working (just for todays test, the weekend test is working).
Hoping someone much more familiar in javascript (which is pretty much anyone other than me, I compiled this from several google searches and a VERY basic understanding of javascript) can point out to me what I am overlooking.
Thank you for your assistance!
Greg
<script type="text/javascript">
function isTodayorWeekend() {
var todaysDate = new Date();
todaysDate.setHours(0,0,0,0);
var tripDate = new Date();
tripDate.setFullYear(document.getElementsByName('pickupdate-year')[0].value);
tripDate.setMonth(document.getElementsByName('pickupdate-month')[0].value);
tripDate.setDate(document.getElementsByName('pickupdate-day')[0].value);
tripDate.setHours(0,0,0,0);
alert('Today is: ' + todaysDate + '\
' + 'Trip Date: ' + tripDate);
if(tripDate.getDay() == 6 || tripDate.getDay() == 0 || tripDate == todaysDate)
{
alert('Not today or weekends!');
}
}
</script>