Jump to content

Date Validation with Javascript


Recommended Posts

Hi,

I have a date field in a Submission form datapage and I want to validate that the entered date is greater than today's date.

I tried something like this but it didnt work.

function validateDate()

{

var del_date = '[@InsertRecordGuestOrders_Delivery_date]';

var today = new Date();

if (del_date <= today)

alert("Delivery date has to be later than today");

}

document.getElementById('InsertRecordGuestOrders_Delivery_date').onChange = validateDate();

Would really appreciate any help.

Link to comment
Share on other sites

Try this: 

<script type="text/javascript"> function validateDate() { var del_date = document.getElementById('InsertRecordGuestOrders_Delivery_date').value; if (Date.parse(del_date) < Date.now()) { alert("Delivery date has to be later than today"); } } document.getElementById('InsertRecordGuestOrders_Delivery_date').onChange = validateDate(); </script>
Link to comment
Share on other sites

Thanks for your response Maymusic.

The validation code seems to work but it doesnt seem to run when the date field is changed. However with an old date, if I reload the page, I get the alert - so the code you suggested seems to work.

I tried both onChange and onClick and neither one works. Do you know what else might?

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

×
×
  • Create New...