I have a page where I am trying to add Children to a Parent object.
On the page, I have a link, "Add Child", that calls an ajax get, returning a partial view with textboxes for the Child. In the sucess, i am doing a function to add the results to the innerHTML of a div.
On the partial view, I have a textbox for the Birthdate, named "Birthdate{id}", where the {id} is a number based on how many have been added.
In the success method, I am then doing a
$("#BirthDate" + childAdded).datepicker();
This works great, for the latest Birthdate date picker. If I add 3 Children, the 3rd Child div's BirthDate will have a datepicker on load, but the 1st and 2nd will lose the datepicker. Adding a 4th will then remove the datepicker from the 3rd.
Code:
function addChild() {
$.ajax({
type: "GET",
url: "/Home/AddChild?childNumber=" + $("#CurrentNumberOfChildren").val(),
data: "{}",
contentType: "text/html",
dataType: "html",
success: function (results) {
var div = document.getElementById('ChildDiv');
div.innerHTML += results;
$("#CurrentNumberOfChildren").val(parseInt($("#CurrentNumberOfChildren").val()) + 1);
var numberOfChildren = $("#CurrentNumberOfChildren").val();
$("#BirthDate" + numberOfChildren).datepicker();
}
});
}
Anyone ever run into this?