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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:03:28+00:00 2026-06-18T16:03:28+00:00

I have dynamically added datepicker textboxes of id’s TrainingPeriodStart[] and TrainingPeriodEnd[] . I need

  • 0

I have dynamically added datepicker textboxes of id’s TrainingPeriodStart[] and TrainingPeriodEnd[]. I need to target each pair to set their proper start and end date.

The setting of the start and end date is found on the documentation link here.

I have the code below in mind but it does not work:

    var inputName = '';
    var number = '';

    $('input[id^="TrainingPeriodStart"]').click(function() {
        inputName = $(this).attr('id');
        number = inputName.substr(inputName.length - 3); // get [number]
    }).datepicker({
        changeYear: true,
        changeMonth: true,
        dateFormat: 'yy-mm-dd',
        onSelect: function( selected ) {
            $('#TrainingPeriodEnd'+number).datepicker( "option", "minDate", 
                selected )
        }
    });

    $('input[id^="TrainingPeriodEnd"]').click(function() {
        inputName = $(this).attr('id');
        number = inputName.substr(inputName.length - 3); // get [number]
    }).datepicker({
        changeYear: true,
        changeMonth: true,
        dateFormat: 'yy-mm-dd',
        onSelect: function( selected ) {
            $('#TrainingPeriodStart'+number).datepicker( "option", "maxDate", 
                selected )
        }
    });

Basically I want to target datepicker pairs with their [number] attribute and setting their minimum and maximum dates to restrict the user from selecting illegal date ranges.

How do I solve this?

  • 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-06-18T16:03:30+00:00Added an answer on June 18, 2026 at 4:03 pm

    If you clone elements, you need to add new click events to the cloned elements in order for the event to be triggered:

    $(function() {
        var inputName = '';
        var number = '';
    
        var template = $('#training .trainingperiod:first').clone(),
            trainingPeriodCount = 1;
    
        var addTrainingPeriod = function(){
            trainingPeriodCount++;
            var trainingPeriod = template.clone().find(':input').each(function(){
                var newId = this.id.substring(0, this.id.length-1) + trainingPeriodCount;
                this.name = this.id = newId; // update id and name (assume the same)
            }).end() // back to .trainingperiod
            .attr('id', 'TrainingPeriod' + trainingPeriodCount) // update attendee id
            .prependTo('#training'); // add to container
    
            $('#TrainingPeriod' + trainingPeriodCount).find('input[id^="TrainingPeriodStart"]').datepicker({
                changeYear: true,
                changeMonth: true,
                dateFormat: 'yy-mm-dd',
                onSelect: function( selected ) {
                    var thisInput = $(this).attr('id');
                    var thisNumber = thisInput.substr(thisInput.length - 3);
                    $('#TrainingPeriodEnd'+thisNumber).datepicker( "option", "minDate", 
                        selected )
                }
            });
            $('#TrainingPeriod' + trainingPeriodCount).find('input[id^="TrainingPeriodEnd"]').datepicker({
                changeYear: true,
                changeMonth: true,
                dateFormat: 'yy-mm-dd',
                onSelect: function( selected ) {
                    var thisInput = $(this).attr('id');
                    var thisNumber = thisInput.substr(thisInput.length - 3);
                    $('#TrainingPeriodStart'+thisNumber).datepicker( "option", "maxDate", 
                        selected )
                }
            });        
        };
    
        $('.add').click(addTrainingPeriod); // attach event
    
        $('input[id^="TrainingPeriodStart"]').click(function() {
            inputName = $(this).attr('id');
            number = inputName.substr(inputName.length - 3); // get [number]
        }).datepicker({
            changeYear: true,
            changeMonth: true,
            dateFormat: 'yy-mm-dd',
            onSelect: function( selected ) {
                $('#TrainingPeriodEnd'+number).datepicker( "option", "minDate", 
                    selected )
            }
        });
    
        $('input[id^="TrainingPeriodEnd"]').click(function() {
            inputName = $(this).attr('id');
            number = inputName.substr(inputName.length - 3); // get [number]
        }).datepicker({
            changeYear: true,
            changeMonth: true,
            dateFormat: 'yy-mm-dd',
            onSelect: function( selected ) {
                $('#TrainingPeriodStart'+number).datepicker( "option", "maxDate", 
                    selected )
            }
        });
    });
    

    Fiddle is here.

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

Sidebar

Related Questions

I have labels that are dynamically added on to the form with each of
I have added dynamically some radio buttons to a jsp page. Now i need
I have a table with dynamically added rows that need to have different properties
I have controls that are dynamically added via javascript. I cannot set the class
I have this code $(.delete2).click(function() { $('#load2').fadeIn(); } I have dynamically added item via
i have a li tag which was dynamically added. To that based on some
I have a table. Some rows are dynamically added by jquery. The first <td>
I have the following element on my page, which gets a dynamically added ID
I have created jframe in which jpanels are added dynamically what i can't do
I have TabControl. I added it to tabpages. To one of them(tpTags) I dynamically

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.