Reputation: 119
I have add button it will add a startdate textbox and end date textbox along with a pop calendar.But the calendar pop up is not working.
UPDATE
$(document).ready(function () {
$(".datepicker").each(function () {
$(this).datepicker();
});
$("#add").click(function () {
$(".container").append('<div class= "Cycleone"> <table> <tr> <td> <label ID="lblStartDate">Start Date </label> </td> <td> <input type="text" id="txtStartDate" class="datepicker"/><label id="lblEndDate" >End Date</label></td><td><input type="text" id="txtEndDate" class="datepicker"/></td></tr></table></div>');
$(".datepicker").datepicker();
})
});
Button
<div class="button">
<input type="button" id="add" name="btnAddAddress" value="Add" />
Please provide a example if possible.Thank you
Upvotes: 2
Views: 343
Reputation: 23836
After adding to pop you can initialize datepicker:
$("#btnAdd").click(function() {
var addelement = $('<div class= "Cycle"> <table> <tr> <td> <label ID="lblStartDate">Start Date </label> </td> <td> <input type="text" id="txtStartDate" class="datepicker"/><label id="lblEndDate" >End Date</label></td><td><input type="text" id="txtEndDate" class="datepicker"/></td></tr></table></div>');
$(this).after(addelement);
$(".datepicker").datepicker();//here
});
Reason: Because you are initializing datepicker on Document ready but pop datepicker is not yet present in DOM.
Updates
You are facing problem because when you adding input boxes you are always giving same id txtStartDate
, txtEndDate
even for label also. ID should be unique across HTML page. Just remove id from JS code:
Upvotes: 3