Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7172281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:35:05+00:00 2026-05-28T15:35:05+00:00

I am trying to get the date selected on page load, which is 4

  • 0

I am trying to get the date selected on page load, which is 4 days onwards from today date on page load, to auto populate my field which is in the sidebar for the user to be able to see which date is selected for delivery.

I have managed to get the date to populate the field, but only once it has been clicked. When the page loads it automatically highlights the current day which means the user could proceed without selecting a date if they just look at the datepicker as my datepicker is visible at all times like a calendar.

I have pasted my code below, my datepicker is in #calendar and the value is populating #alternate. What I need is #alternate to be auto populated in the same date format on page load, as at the moment it is blank until you click a day.

<script type="text/javascript">
$(function() {
$( "#calendar" ).datepicker({ minDate: +4, maxDate: "+1M +4D", dayNamesMin: ['Mon', 'Tue',        'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], prevText: '<<', nextText: '>>', changeMonth: false, changeYear: false, altField: "#alternate", altFormat: "DD, d MM, yy", gotoCurrent: false, defaultDate: '+4'});}); 
</script>

 <div id="calendar"></div>

 <input type="text" id="alternate" name="delivery-date"/>

Any help would me much appreciated.

EDIT

<script type="text/javascript">
$(function() {
$( "#calendar" ).datepicker({ minDate: +4, maxDate: "+1M +4D", dayNamesMin: ['Mon', 'Tue',    'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], prevText: '<<', nextText: '>>', changeMonth: false, changeYear: false, altField: "#alternate", altFormat: "DD, d MM, yy", gotoCurrent: false,  defaultDate: '+4'});
var today = new Date();
today.setDate(today.getDate()+4);
future =(today.getMonth()+1) + '/' + today.getDate() + '/' + today.getFullYear();

$("#alternate").append($.datepicker.formatDate('D, dd M yy', today));
});
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:35:06+00:00Added an answer on May 28, 2026 at 3:35 pm

    You can find the answer in a previous stackoverflow question here:

    How do I pre-populate a jQuery Datepicker textbox with today's date?

    Always worth a quick Google search 😉

    Making that code specific to your code would be something like:

    var today = new Date();
    today.setDate(today.getDate()+4);
    future =(today.getMonth()+1) + '/' + today.getDate() + '/' + today.getFullYear();
    
    $("#alternate").val(future);
    

    Here’s a jsfiddle live version: http://jsfiddle.net/NXFy2/


    EDIT: You could use the datepicker built in formatting to format a new date actually:

    $.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));
    

    See the examples and docs here: http://docs.jquery.com/UI/Datepicker/formatDate


    FURTHER EDIT: To use the datepicker formatDate function together with the initial code to get the date today or however many days from today you could do the following:

    $( "#calendar" ).datepicker({ minDate: +4, maxDate: "+1M +4D", dayNamesMin: ['Mon', 'Tue',    'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], prevText: '<<', nextText: '>>', changeMonth: false, changeYear: false, altField: "#alternate", altFormat: "DD, d MM, yy", gotoCurrent: false,  defaultDate: '+4'});
    
    var today = new Date();
    today.setDate(today.getDate()+4);
    
    $("#alternate").val($.datepicker.formatDate('D, dd M yy', today));
    

    Here is the jsfiddle: http://jsfiddle.net/xX5AM/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to get date from my implementation of jquery date picker, add
I am trying to get the offset hours from UTC, given a summer date.
I am trying to get the week of a date from the database and
I'm trying to get selected dates using two date and time picker (like fromdate
With ruby I'm trying to get format a date as such: 2009-10-01 Where I
For example, I am trying to get a min date, a max date, and
I am trying to get an array of a date plus the next 13
I am trying to get a attribute of a date picker to pull the
I'm trying to get the unix time for date strings that are formatted like
I'm trying to get the week range using Sunday as the start date, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.