If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Onchange doesn't detect change on date field?

Good evening/morning
I have 2 fields - start date (pickupdate) and end date(dropoffdate) with a datepicker on both.
When the user picks a start date I would like to change the end date automatically to start date+3 days.
I added an onchange to my input field with a call of a javascript function

I tried adding the 3 days in a function and nothing happened so I just created a text field and asked the function to write "test" in the text box when the pickup date is changed but even that doesn't work:

I am obviously doing something glaringly wrong . Please could someone give me an indication of where I am going wrong?
the website is www.carhirecappadocia.com and my complete script is below. Thank you in advance to anybody who could give me some advice.

onchange fires on text inputs when the input loses focus (making the difference between it an onblur to me seem meaningless) - try entering something in your box and then clicking on another part of the page - the event should fire. If you want the value in the second box to appear as soon as the first box is filled (which I guess happens from the datepicker) you would have to find the function in the datepicker that fills the first box and get it to fill the second box at that time too. html5 has an oninput event that could help you here, but it is only supported by modern browsers

I think I am getting out of my depth here as it would mean getting into the entrails of the jquery ui datepicker script so I think I'll decide it will be a "nice to have" for a future date. I still have yet to struggle with the date validations (> today, start date < end date) and the difference in days between the 2 dates.
Thank you again.

Thank you for the encouragement, I'm definitely a bit lost and have just started looking at the moment.js library but I'll try to take things one at a time and work it out for myself before bothering you with more posts.

But I still have some issues:
- if pickupdate is 28/12/2012 dropoffdate becomes 31/0/2013
- the pickupdate datepicker window doesn't close when the date is picked
- the number of days difference doesn't always re-caclulate
Any ideas where I am going wrong?(www.carhirecappadocia.com)
Thank you for your patience.

That is great -thank you!!!!!
I just changed the minimum date to dt rather than end (I just wanted the default frop off date to be 3 days after the pick up but to be able to change up until same day as pick up but not before).
Anyway., thank you again, that is really helpful and I've learned a lot rather than just copying snippets of code.

which is a good point. the javascript date object uses months with a zero index (so January is 0, February is 1, etc) which is why you need to subtract one when you take a humanly-readable date and make it into a date object (and the reverse when you're going the other way).