I am trying to create a div with textbox on which i want datepicker to display date. So far i am able to dynamically create the div with textbox and datepicker but i am not being able to display the date on textbox. What am i doing wrong here??
Code:
showdate(){
var newDateBoxdiv = $(document.createElement('div')).attr({ class:"EDate", id:"EDate"+i});
newDateBoxdiv.html('<input type="text" id="DisplayTextBox">');
addDateBox();
newDateBoxdiv.insertAfter('.EDate');
}
//Function called inside the above function
addDateBox(){
$('.EDate').find('input[id^="DisplayTextBox"]').each(function () {
$(this).datepicker({
showOn: "button",
buttonImage: "calendar.png",
buttonImageOnly: true
});
$(this).datepicker({dateFormat: 'dd-M-y'});
var dateFormat = $( this ).datepicker( "option", "dateFormat" );
$(this).datepicker( "option", "dateFormat", 'dd-M-y' );
});
Updated code.. Ive noticed some errors of your code including the newDateBoxdiv values. Your textbox DisplayTextBox is not incrementing as well. Try this instead.