I am working on a form to request parking validation. There are two controls on the form that I'm concerned with, an arrival datetime and departure datetime. What I'd like to do is when the DATE of one of these controls is changed, I'd like for that date to copy into the other control. The time portion should not change. Additionally, I want to be able to calculate the difference between these two times via a calculated field, which is currently working properly when the dates are manually selected from the datepicker.
The code snippet below is the closest I've been able to get. When the arrival time is changed, the empty date constructor sets dateEntered to the current date, and the current date properly copies into the second control on the form. As desired, the Time fields do not appear to be affected. However, I cannot figure out how to create the date object with the value from the arrival time control so it behaves in a similar fashion. When I try adding additional lines of code to store the date, the value stops copying altogether, so I'm having difficulty determining where the breakdown is and if it's a syntax error or an issue with how the date is formatted.
// Set up an on-change event for the Departing date box to copy the date value to Returning
var dateEntered = new Date();
var inpArriving = NWF$("#" + v_arrTime);
//var dateEntered = NWF$("#" + v_arrTime).val();
NWF$("#" + v_depTime).val((dateEntered.getMonth()+1) + "/" + dateEntered.getDate() + "/" + dateEntered.getFullYear());
In the above code, if I swap the comments on the var dateEntered assignments, the alert does not come through. I've seen the same operation in numerous posts so I don't believe this is a syntax error but is more likely an issue with my lack of understanding regarding how the dates are stored and how they need to be manipulated to properly populate the control on the form.
Could anyone help me to understand what I need to do to implement this on-change function and achieve the desired results? Or if you have a more simple solution/approach you'd like to suggest, please let me know. I'm open to suggestions Thanks!!