Hi everyone, I'm working in a project where its required a dynamic insertion of a grup of 3 textfields where one hiels dates. So far I manage to do the insertion part, but Im still with the problem of jquery datepicker only working right on the first(original) textfield. I notice an error when inserting new textfield and trying to access the jquery datepicker "Uncaught TypeError: Cannot read property 'append' of undefined"!

I searched the web and i found that it can ve fixed by creating a class on the textfield and adding "'removeClass' or the 'not' ".

$('.datepicker').removeClass('hasDatepicker');

I tried both but nothing!
How can I resolve this? the id of the textfield its the same for the textfield that are created at the moment! Don't know what to do, but i will continue researching and if I can resolve it I will post here the solution for those with the same problem.

Recommended Answers

All 5 Replies

jQuery('.date-pick').removeClass('hasDatepicker').datepicker({
    dateFormat: 'mm-dd-yy'
    });

Hi eburlea thanks for your reply, but your code didn´t worked for me! It should had! I´m going to continue trying to solve this problem! once again thanks for your help

Member Avatar for iamthwee

For one ids should be unique, follow the w3c standards.

Hi imathwee, Im now creating a way to insert an unique id to the textfields and a loop them all on the datepicker, thanks for your reply

Hello to everyone I was able to resolve my problem, by creating textfield with an unique id and search for those id's with the datepicker.
Thanks to all who offered them selves to help me wih this.
Here's what I done for those of may incounter the same problem

var intTextBox=0;

function addTable_textbox()
{
intTextBox = intTextBox + 1;
var contentID = document.getElementById('content');
var newTBDiv = document.createElement('div');
newTBDiv.setAttribute('id','strText'+intTextBox);
newTBDiv.innerHTML = "<table id='dataTable' width='670' border='1'><tr><td width='30' height='42'><input type='checkbox' name='chk'/></td><td width='42'><p> Nome </p></td><td width='144'><input type='text' name='txt[]'/></td><td width='113'> Data nascimento</td><td width='144'><input type='text' class='date-pick'  name='txt2[]' id='" + intTextBox + "' /></td><td width='88'><p>Frequenta ipt </p></td><td width='413'><input type='text' name='txt3[]'/></td></tr></table>";
contentID.appendChild(newTBDiv);


$(document).ready(function() {
    $('#'+intTextBox).removeClass('hasDatepicker').datepicker({
        //$(this).datepicker('destroy').datepicker({
        dateFormat:'yy/mm/dd', 
        changeMonth: true,
        changeYear: true,
        yearRange: "1945:", 

  });
    });

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.