Jump to content

Archived

This topic is now archived and is closed to further replies.

artdocent

Check That A Date Is Not A Saturday, Sunday Or Monday

Recommended Posts

In my submission form, the user selects a date for a lesson. I would like to use javascript to check that the date selected is not a Monday, Saturday, or Sunday. Can anyone help?

 

It would be great if the script also checked that the date is not in the past.

 

I've been sifting through all sorts of JS, and I know it must be possible, but I'm a newbie. Thanks for your help.

Share this post


Link to post
Share on other sites

Figured it out! I modified script I found in another reply to include checking for the day. My script checks that the date is after today, and it is not a Saturday, Sunday or Monday.

 

 function checkStart()
{
   var v_sDate = document.getElementById("InsertRecordBooking_Date").value;
   var sDate = new Date(v_sDate);
   var nDate = new Date();
   nDate = Date.now();
   var setToday = sDate.getDate() + 1;
   sDate.setDate(setToday);
   
   var setDay = sDate.getDay();
   
   if (sDate<nDate)
      {
         alert("Your requested lesson date is before today.");
         return false;
      }
      else
        {
            if (setDay == 0 || setDay == 1 || setDay == 2)
              {
                  alert("Your requested lesson date is a Saturday, Sunday or Monday. Please choose a new date.");
                  return false;
              }
        }
}   
 
document.getElementById("caspioform").onsubmit=checkStart;
 

Share this post


Link to post
Share on other sites

×
×
  • Create New...