0

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.

3
Contributors
5
Replies
41
Views
4 Years
Discussion Span
Last Post by Dimonai
0
jQuery('.date-pick').removeClass('hasDatepicker').datepicker({
    dateFormat: 'mm-dd-yy'
    });
0

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

0

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

0

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:", 

  });
    });

}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.