Jump to content
  • 0
Sign in to follow this  
logistics

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

Share this post


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

Share this post


Link to post
Share on other sites
  • 0

I would suggest the footer.**

 

Put this code in the "Source" of the Footer by clicking the "<>" button, or disable the HTML editor as you mention.

 

 

**Code in the Footer often helps performance.

**Code in the Header allows you to do stuff before the pages loads.

Share this post


Link to post
Share on other sites
  • 0

Hi Guys,

 

I have one date field which is a display field called "result date". And there is a date field called "Date of Joining". I want to restrict "Date of joining" basis of "Result date". I dont want my user to choose "Date of Joining" which is earlier than "Result Date". Any one knows the solution? thanks in advance.

Share this post


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...
Sign in to follow this  

×
×
  • Create New...