DavidKennett

Not allow a date in the future from being selected from date/time field type

4 posts in this topic

 

I have the same issue where i have implemented the below script but it is still allowing me to select a date in the future from the date/time.

 

<script>
function pastDateValidation()
{
    var d=document.getElementById("InsertRecordClient_AML_Date").value;
        if(new Date(d) > new Date())
    {
        alert("Select a date which is before now");
        document.getElementById("InsertRecordClient_AML_Date").value="";
    }

}
document.getElementById('InsertRecordClient_AML_Date').onchange = pastDateValidation;

</script>

 

I've been told by support that because i'm using UK localization the script may need changing. It works in US localization. Would anyone know what i would need to change for it to work in UK localization please?

Share this post


Link to post
Share on other sites

Hello DavidKennett,

You should convert your dates with toLocaleDateString() method in order to compare two dates with different locals. 

This code should do the trick.

<script>
function pastDateValidation()
{
    var d=new Date(document.getElementById("InsertRecordClient_AML_Date").value);
    var c =  new Date();
  
        if(c.toLocaleDateString() > d.toLocaleDateString())
    {
        alert("Select a date which is before now");
        document.getElementById("InsertRecordClient_AML_Date").value="";
    }
}
document.getElementById('InsertRecordClient_AML_Date').onchange = pastDateValidation;

</script>

Regards,

vitalikssssss

Share this post


Link to post
Share on other sites
21 hours ago, DavidKennett said:

Thank you for that script. I've added that, but it doesn't seem to have had any effect. I can still select a date in the future via the time/date field and it allows me to submit the submission form. 

Do you use the code in Submission Form?

Have you placed the code in Footer of the Datapage?

Please make sure that you have specified a correct name of the field.

You can send me a deploy URL of Datapage via PM, in order for me to have a brief look at the issue via browser developer tools.

 

Regards,

vitalikssssss

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now