Jump to content

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.

Link to comment
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;
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...