Jump to content

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


Recommended Posts

 

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?

Link to comment
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

Link to comment
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

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