2

When a form load I want it to already have the current date plus 5 days. So its 2/22/2011, When the page loads the text box the datepicker belongs to should show 3/1/2011. I know how to set default date to 5 days from the current date but I need it to be in the text box when the page loads.

2 Answers 2

5

There is actually a much easier way.

$("#datepicker").datepicker();
$("#datepicker").datepicker("setDate", "+5d");

Just figured it out.

Sign up to request clarification or add additional context in comments.

Comments

1

I must be missing something, you would do something like:

$(function() {
    //set your date picker
    $('#test').datepicker();

    //get the current date
    var yourDate = new Date();
    //set the current date to today + 5 days
    yourDate.setDate(yourDate.getDate() + 5)
    //format the date in the right format
    formatDate = (yourDate.getMonth() + 1) + '/' + yourDate.getDate() + '/' + yourDate.getFullYear();
    //set the input value
    $('#test').val(formatDate);
});

Working sample here here...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.