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 5992457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:32:04+00:00 2026-05-22T23:32:04+00:00

I have a datepicker input that is populated with today’s date when the page

  • 0

I have a datepicker input that is populated with today’s date when the page loads. When datepicker is used, the date is split into month, day, and year and put into three hidden fields that are sent to the sever with the post data. The problem comes when the user decides today’s date is fine and doesn’t use the datepicker; how do I get the date pieces into those three hidden fields?

I tried breaking out today’s date into pieces and adding it to those fields but every way I’ve tried to add it into jQuery or using plain JavaScript breaks the whole thing. Here is the working code that I’d like to build on:

jQuery

$(function() {
    //set your date picker
        $("#CI").datepicker({
        dateFormat: 'mm/dd/yy',
        changeMonth: true,
        changeYear: true,
        showOn: "both",
        buttonImage: "css/images/calendar-green.gif",
        buttonImageOnly: true,
        buttonImageText: "Calendar",
        beforeShow: function(dateText, instance) { 
            $("#CI").datepicker('setDate', new Date());
        },
        onSelect: function(dateText, instance) {
            var pieces = dateText.split("/");
             $("#CID").val(pieces[0]);
             $("#CIM").val(pieces[1]);
             $("#CIY").val(pieces[2]);
         }                
    })

    //get the current date
    var todaysDate = new Date();
    //format the date in the right format (add 1 to month because JavaScript counts from 0)
    formatDate = (todaysDate.getMonth() + 1) + '/' + 
                         todaysDate.getDate() + '/' + 
                         todaysDate.getFullYear();
    //set the input value
    $('#CI').val(formatDate);       
});

HTML

<input type='text' id='CI' name="CI">
<input type="text" name="CID" id="CID" />
<input type="text" name="CIM" id="CIM" />
<input type="text" name="CIY" id="CIY" />
  • 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-22T23:32:04+00:00Added an answer on May 22, 2026 at 11:32 pm

    Split out your onSelect() functionality into a separate function, which can them be called twice.

    Having the same function performing both tasks allows you to deal with any changes to your functionality or HTML structure.

    so…

    $(function() {
        function populateHidden(dateText){
            var pieces = dateText.split("/");
            $("#CID").val(pieces[0]);
            $("#CIM").val(pieces[1]);
            $("#CIY").val(pieces[2]);
        }
        //set your date picker
        $("#CI").datepicker({
            dateFormat: 'mm/dd/yy',
            changeMonth: true,
            changeYear: true,
            showOn: "both",
            buttonImage: "css/images/calendar-green.gif",
            buttonImageOnly: true,
            buttonImageText: "Calendar",
            beforeShow: function(dateText, instance) { 
                $("#CI").datepicker('setDate', new Date());
            },
            onSelect: populateHidden
        })
    
        //get the current date
        var todaysDate = new Date();
        //format the date in the right format (add 1 to month because JavaScript counts from 0)
        formatDate = (todaysDate.getMonth() + 1) + '/' + 
                             todaysDate.getDate() + '/' + 
                             todaysDate.getFullYear();
        //set the input value
        $('#CI').val(formatDate); 
        populateHidden(formatDate); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple page that's using jquery's datepicker. I have: <input id=datepicker
I have a textfield that users input the date using a modified jquery datepicker.
I have an input field that is being set as a date picker. When
I have: <script> $(function() { $( #datepicker ).datepicker(); }); </script> <div class=demo> <p>Date: <input
Consider that I have 10 input boxes, (using datepicker plugin Fyi) I have a
I have an input field that I define as a datepicker through a css
I have a datepicker that I create with the following code. $('.myClass').find('input').datepicker({showOn: 'button', buttonText:
I have this Editor Template so that I have a datepicker set for date
I have 2 input fields and i am using it with a DatePicker like
I have a jQuery datepicker that I want to restrict non work days -

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.