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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:12:51+00:00 2026-05-27T07:12:51+00:00

With my very limited knowledge of both jQuery and JS i made a small

  • 0

With my very limited knowledge of both jQuery and JS i made a small script (with the help of Nicola Peluchetti) that duplicates a tablerow when a button is clicked. This works like a charm, however, i would like to add a datepicker to it. This also works well, but just once and not on the copied fields or visa versa. It’s probably because the datepicker “thinks” there is just one field.

I found several sources to solve the problem, but again, with my newbie knowledge, it’s just to hard. I am playing with this for almost two days and can’t get it solved.

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$("input[type='button'].AddRow").click(

function() {
var index = $(this).closest('tr').index();
if (index > 0) {
$(this).closest('tr').remove();
} else {
$(this).closest('tr').clone(true).prependTo($(this).closest('table'));
$(this).val(i++);
/* $('.startdatum').removeClass('hasDatepicker').datepicker({dateFormat: 'mm-dd-yy'});    */
 }

});
});//]]> 
</script>

HTML

<table width="960" border="0" align="center" cellpadding="10" cellspacing="0"     class="contentblock">
<tr>
<td width="140"><strong>Startdatum</strong></td>
<td><input name="startdatum[]" type="text" class="startdatum" value="dd/mm/jjjj" />
<script>
$(function() {
    $('.startdatum').removeClass('hasDatepicker').datepicker({
dateFormat: 'mm-dd-yy'
});
});
</script>
  <select name="locatie[]" id="locatie[]">
    <option value="" selected></option>
  </select></td>
  <td width="143"><strong>Dekking</strong></td>
  <td width="133"><select name="dekking[]" id="dekking[]">
  <option value="" selected></option>
  </select></td>
  <td width="145"><input type="Button" value="Add Row" class="AddRow"></td>
  </tr>
  </table>

Potential solutions that i don’t get:

  • http://www.stemkoski.com/problem-with-jquery-ui-datepicker-dynamic-dom/
  • duplicating jQuery datepicker
  • Dynamic JQuery date picker code

Datepickerplugin:

  • http://jqueryui.com/demos/datepicker/

Could anyone please help me out?

  • 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-27T07:12:52+00:00Added an answer on May 27, 2026 at 7:12 am

    one solution is to destroy the datepickers and rebuild them after adding different ids to them. I changed your code a little:

    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all">
    <table width="960" border="0" align="center" cellpadding="10" cellspacing="0"     class="contentblock">
    <tr>
    <td width="140"><strong>Startdatum</strong></td>
    <td><input id='datePicker' name="startdatum[]" type="text" class="startdatum" value="dd/mm/jjjj" />
      <select name="locatie[]" id="locatie[]">
        <option value="" selected></option>
      </select></td>
      <td width="143"><strong>Dekking</strong></td>
      <td width="133"><select name="dekking[]" id="dekking[]">
      <option value="" selected></option>
      </select></td>
      <td width="145"><input type="Button" value="Add Row" class="AddRow"></td>
      </tr>
      </table>
    
    <input type="hidden" value="0" id="counter">
    
    $('.startdatum').removeClass('hasDatepicker').datepicker({
        dateFormat: 'mm-dd-yy'
    });
    
    
    $("input[type='button'].AddRow").live('click',
    function() {
        var index = $(this).closest('tr').index();
        if (index > 0) {
            $(this).closest('tr').remove();
        } else {
    
    
            var $tr = $(this).closest('tr').clone(true);
            var $input = $tr.find('input.startdatum');
            var index = $('input#counter').val();
            var id = 'datepicker' + index;
            index++;
            $('input#counter').val(index);
            $input.attr('id', id).data('index', index);
            console.log(index);
            $tr.prependTo($(this).closest('table'));
            $('.startdatum').each(function() {
                $(this).datepicker('destroy');
                $(this).datepicker({
                    dateFormat: 'mm-dd-yy'
                });
            });
    
        }
    
    });
    

    fiddle here http://jsfiddle.net/nicolapeluchetti/87QCx/1/

    Edit – if you need to attach the row after all the others:you must change

            $tr.prependTo($(this).closest('table'));
    

    in

            $(this).closest('table').append($tr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very limited knowledge with scripts so I hope you guys can help
My knowledge of JS is very limited and i need help in validating this
My SQL knowledge is very limited, specially about SQLite, although I believe this is
I have a very limited knowledge about node and nob-blocking IO so forgive me
I have very limited knowledge of C#. My goal is to provide a C++
I've got very limited knowledge about Erlang, but as far as I understand, it
I'm very new to this and have limited knowledge (all self taught over the
I'm very new to rails so please forgive my limited knowledge. If I wanted
I have very limited coding knowledge of OpenGL/Glut. I'm supposed to build house and
As a UI devloper and someone with very limited Java knowledge, how do I

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.