Solved

How to use datepicker with dynamic table

Posted on 2013-01-29
2
388 Views
Last Modified: 2013-01-29
I am trying to use jQuery datepicker with a dynamic table. The problem I am having is that the date picker keep changing the date in the first row. The codes I am currently using is as follows:-

<script>
$( document ).ready(function() {

  $(function()

        {
            $(".datepicker").datepicker({dateFormat: "dd M yy", changeMonth: true, changeYear: true,Anim:"Clip"});

            $(".datepicker").attr('readOnly', 'true');

        }
    );

    $(".button").click(function() {

                var $currentrow= $(this).closest('tr');
                $(".datepicker").datepicker("destroy")
                var $newrow=$currentrow.clone(true);
                $newrow.find('input:text').val('');
                $newrow.find(".datepicker").datepicker({dateFormat: "dd M yy", changeMonth: true, changeYear: true,Anim:"Clip"});
                $newrow.appendTo('tbody');

            })

        });

</script>

Open in new window


So what do I need to do to insert the date into the new row.

Thanks
0
Comment
Question by:Sheils
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38830800
Test page : http://jsfiddle.net/F5cPx/
$( document ).ready(function() {
    $(".datepicker").datepicker({dateFormat: "dd M yy", changeMonth: true, changeYear: true,Anim:"Clip"});
    $("table").on("click", ".button", function() {
        var $newrow = $(this).closest('tr').clone().appendTo('table');
        var id = "dp"+new Date().getTime();
        $newrow.find('.datepicker').attr({"id":id}).val("").removeClass("hasDatepicker");
        $("#" + id).datepicker({dateFormat: "dd M yy", changeMonth: true, changeYear: true,Anim:"Clip"});
    })
});

Open in new window

0
 
LVL 16

Author Closing Comment

by:Sheils
ID: 38834190
Thanks Mate
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now