I have a form for event registration under my site that contains two time select fields, an arrival time and departure time. What I want to do is to have the number of hours between these two times calculated and displayed in the 'Total Hours' field automatically before the form is submitted if possible. I'm thinking that I'll need a bit of jQuery to accomplish this or perhaps by using the entry_submission_start hook. Any tips or examples for accomplishing this would be greatly appreciated! Thanks
Start by converting the dates/times into timestamps. This will allow you to subtract one from the other. Then convert the resulting timestamp back into hours. You may also find that momentjs would be useful for this but is probably not necessary.
If you don't need this to work on other sites and you know the names of the fields it should be simple.
Look at http://pkg.io for a good starting point to get the necessary outline for you Accessory.
I very quickly put together an Accessory for you. You'll need to change the field names within the views/accessory_datecalc.php file. Use with caution as it's very rough! Download it here
<span id="time_spent"></span> to display the total.