maverick Posted March 29, 2013 Report Share Posted March 29, 2013 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. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 29, 2013 Report Share Posted March 29, 2013 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> Quote Link to comment Share on other sites More sharing options...
maverick Posted March 30, 2013 Author Report Share Posted March 30, 2013 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.