Link to home
Start Free TrialLog in
Avatar of kiwistag
kiwistagFlag for New Zealand

asked on

Javascript auto update date field for duration

Similar to: Javascript date function to calculate the end date using the duration

I have a website & need part of the form to autocalculate the end date (30 days from the entry date) after the month field has been entered.

The fields in use are StartDD, StartMM, StartYYYY.

At present I have the input text fields linked with auto clear & auto-hop
I.E
Start Date: (DD) - (MM) - (YYYY)
Jumping into DD will clear the DD text, typing in 2 numbers in DD will jump it into the MM box & so on.

At present the YYYY field is auto-populated however this may have to change at the end of the year.

Any helps with examples would be great
Avatar of Amick
Amick
Flag of United States of America image

<script type="text/javascript">
var d=new Date();
d.setFullYear(YYYY,MM-1,DD);
document.write(d,'<br \>');
d.setDate(d.getDate()+30);
document.write(d);

</script>
Note that month is zero based - 0=January
ASKER CERTIFIED SOLUTION
Avatar of Amick
Amick
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cut and paste error above, in development I saw calling the function updateDate and changed it to addDays, before I pasted it in.  Clearly, the function addDays is called using the function name addDays rather than updateDate. I apologize for the error.