Jump to content
  • 0

Restrict Date Fields


Question

Hello all,

 

I am in the middle of creating a submission form.

It will have two dates: a start date and end date, both selected from a calendar.

The start date is compulsory.

The end date is not compulsory.

 

When the user inputs the start date, on clicking out of the field, I need the form to check if the date is both greater to or equal to 25 April 2016, AND less than or equal to 01 May 2016.

If it is incorrect, I need a message to be displayed indicating the error, and stopping the user from moving on.

 

If the user decides to input an end date, on clicking out of the field, I need the form to check if the date is both greater to or equal to the start date, AND less than or equal to 01 May 2016.

If it is incorrect, I need a message to be displayed indicating the error, and stopping the user from moving on.

 

How can I achieve this?

 

Thanks in advance, 

Julien

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hello Julien, try the code below

<script>
function checkdate(){
var v_sDate = document.getElementById("InsertRecorddate").value;
var sDate = new Date(v_sDate);

var endD= new Date("04/25/2016");

var startD=new Date("05/01/2016");
if (sDate>=endD && sDate<=startD){

alert("enter a different date");
return false;
}
}
document.getElementById("InsertRecorddate").onblur=checkdate;
document.getElementById("caspioform").onsubmit=checkdate;
</script>

Replace InsertRecorddate with the actual date field ID

Link to post
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
Answer this question...

×   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...