Adding 1 year from current date

Posted by Awebb under JavaScript on 1/6/2015 | Points: 10 | Views : 816 | Status : [Member] | Replies : 2
I'm a JavaScript novice and had a quick question. I have a form that has a Date Form Completed Box that has been set up to automatically add the date the form is opened. At the end of the form I have a box Expire Date that needs to be one year from the Date Form Completed Date. How do I have that box auto-fill for one year from the Date Form Completed box?

thanks
Anthony




Responses

Posted by: Bandi on: 1/6/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
var curDate = new Date();
curDate.setYear(curDate.getFullYear() + 1);
event.value = util.printd("mm/dd/yyyy", curDate);


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Awebb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 1/7/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
You have a text box having id "dateFrom" and as you explained, it has been set up to a default value when the form loaded.
now you have another text box having id "dateExpire",
below is the code to set the date after ONE year,

var  txtFrom=document.getElementById('dateFrom').value;

var dateFrom = new Date(txtFrom);
dateFrom.setFullYear(dateFrom .getFullYear() + 1);
document.getElementById('dateExpire').value=dateFrom;


Thank you,
Govind

Awebb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response