Use Javascript to compare time ranges in PDF form


I have a PDF form with 6 different time periods for each day of the month and I need to make sure those time periods do not overlap when the user completes them. Not all time periods may be completed, but the ones that do must be unique. I have taken inspiration from this previous post Use JavaScript to compare time ranges specifically the contribution by @RobG. However, my lack of scripting knowledge is hampering my ability to mold that code for my specific application. In addition to have the time periods verified, I also have to repeat this for every day on the form but I would like to do it one day at a time particularly when the entries are made for that day. Since this is a PDF form, I am not certain how to execute that validation. For example, should it execute every time a time period is completed? That is, have a Start Time and and End Time? So it would act as a "validation" script for that time entry?
Here is a sample of what the form looks like:



enter image description here



Here is my attempt at updating the code for my form:



In this sample I spelled out the field names, but because I will be repeating this for up to 31 days at a time, I would like to find a way to create a document script where I can put in the 'TimeIn' and 'TimeOut variables and call them for each day, but I think I can get away without that if necessary, just concerned about form size repeating that much code for 6 periods for potentially 31 days. Thank you!



Edit: Time values are HH:mm






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

大跃进

马相伯