I'm attempting to create something of range system for booking rooms on a hotel website and I'm using jQuery UI Datepicker to allow the user to select their check in date. What I then want to do is create another field that's simple "Number of Nights" and have jQuery Datepicker take the check in date, add the number of nights, and set the resulting date as the value of a hidden input (in the correct date format). It would look something like this:
<input type="text" name="arrivalDate" class="datepicker">
<input type="text" name="numOfNights">
<input type="hidden" name="departureDate" value="arrivalDate + number of nights">
Is this possible? Thanks in advance.
(Note: The database I'll be "get"-ing from with this form is a little temperamental and I don't have access to it beyond just a few query-able values.)
The above can be achieved by following code -
You can update the value of the hidden field in the onSelect events for the arrivalDate datepicker.
You'll have to also update the departureDate field from the change event of the numOfNights field.
Try it out here: http://jsfiddle.net/JKGvD/
You'd probably want to make that a function and also use it to initialize the departureDate if your arrivalDate has an initial value.
Use the setDate function.