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

  • SEARCH
  • Home
  • 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 7682871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:40:02+00:00 2026-05-31T18:40:02+00:00

I have 2 sets of input boxes: 1) Start Date I and End Date

  • 0

I have 2 sets of input boxes:

1) “Start Date I” and “End Date I”

2) “Start Date II” and “End Date II”

as it can be seen here: http://jsfiddle.net/YXzpj/

What I need is that whenever user sets the start and end dates of one side, chosen values should be copied to the other side.

For example:
User sets “Start Date I” and then “End Date I”, then the script should automatically copy both values to “Start Date II” and “End Date II”. If user changes any of the four fields, the form should update itself accordingly. In other words, these two sets of input boxes should mirror each other.

Here is my current code:

$(function() {

    var currentTime = new Date();


    $('#report2from1').attr('readonly','readonly');
    $('#report2to1').attr('readonly','readonly');    
    var dates1 = $( "#report2from1, #report2to1" ).datepicker({
        showButtonPanel: true,            
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        minDate: new Date(2010, 1 -1, 1),
        maxDate: new Date(currentTime.getFullYear(), 11, 31),
        dateFormat: "yy/mm/dd",
        onSelect: function( selectedDate ) {
            var option = this.id == "report2from1" ? "minDate" : "maxDate",
                instance = $( this ).data( "datepicker" ),
                date = $.datepicker.parseDate(
                    instance.settings.dateFormat ||
                    $.datepicker._defaults.dateFormat,
                    selectedDate, instance.settings );
            dates1.not( this ).datepicker( "option", option, date );
            if ( this.id == "report2from1" ){
                dates1.not( this ).datepicker( "setDate", date );
            }
        }
    });    

    $('#report2from2').attr('readonly','readonly');
    $('#report2to2').attr('readonly','readonly');
    var dates2 = $( "#report2from2, #report2to2" ).datepicker({
        showButtonPanel: true,    
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        minDate: new Date(2010, 1 -1, 1),
        maxDate: new Date(currentTime.getFullYear(), 11, 31),
        dateFormat: "yy/mm/dd",
        onSelect: function( selectedDate ) {
            var option = this.id == "report2from2" ? "minDate" : "maxDate",
                instance = $( this ).data( "datepicker" ),
                date = $.datepicker.parseDate(
                    instance.settings.dateFormat ||
                    $.datepicker._defaults.dateFormat,
                    selectedDate, instance.settings );
            dates2.not( this ).datepicker( "option", option, date );
            if ( this.id == "report2from2" ){
                dates2.not( this ).datepicker( "setDate", date );
            }                
        }
    });


});
  • 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-31T18:40:03+00:00Added an answer on May 31, 2026 at 6:40 pm

    The Datepicker plugin has an option to do automatically what you are looking: altField

    altField
    Selector, jQuery, ElementDefault:”
    The jQuery selector for another field that is to be updated with the selected date from the datepicker. Use the altFormat setting to change the format of the date within this field. Leave as blank for no alternate field.

    Here’s how I would optimize your code:

    $(function() {
    
        var currentTime = new Date(),
            // cache your selection already
            $dateFields = $('#report2from1, #report2to1, #report2from2, #report2to2');
    
        // set all fields to readonly
        $dateFields.attr('readonly', 'readonly');
    
        // the options are the same for all instances
        var options = {
            showButtonPanel: true,
            changeMonth: true,
            changeYear: true,
            numberOfMonths: 1,
            minDate: new Date(2010, 1 - 1, 1),
            maxDate: new Date(currentTime.getFullYear(), 11, 31),
            dateFormat: "yy/mm/dd",
            // set the date on open so the populated date is selected in the widget
            beforeShow: function(input, instance) {
                $(input).datepicker('setDate', $(input).val());
            }
        };
    
        // instanciate datepicker with the options for all the fields
        $dateFields.datepicker(options);
    
        // apply separately the option 'altField' accordingly
        $('#report2from1').datepicker('option', 'altField', '#report2from2');
        $('#report2from2').datepicker('option', 'altField', '#report2from1');
        $('#report2to1').datepicker('option', 'altField', '#report2to2');
        $('#report2to2').datepicker('option', 'altField', '#report2to1');
    
    });​
    

    DEMO

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

Sidebar

Related Questions

I have sets of 5, 6 and 7 digit numbers. I need them to
I have a form that sets input fields as enabled / disabled based on
I have a jquery calendar that sets the input value to MM/DD/YYYY How would
I have 2 sets of 4 input fields in my HTML Form. I expect
I have 3 sets of 4 input fields that I want the user to
I have two sets of of input fields like this, differentiated by their classes:
I have a number of sets of input fields on page, like this: <div
I have a function that sets text input's to whenever they are clicked/focused on.
I have a button that when clicked sets the text in an input text
The problem in my case is I can dynamically add / remove input boxes,

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.