I have a date picker function that is supposed to turn an input field into a datepicker.
it runs something like this;
function activateDatePicker(id){
$(function() {
$(id).datepicker({
defaultDate: "+1w",
dateFormat: "yy-mm-dd",
changeMonth: true,
changeYear: true,
numberOfMonths: 3,
});
});
}
Another function would create the input tag necessary and call the activateDatePicker function in order to turn it into a jquery datepicker, for example
function createInputTag(input){
document.getElementById("sometag").innerHTML =
"<input id="+input+" />";
activateDatePicker(input);
}
That input could be anything, and I would use createInputTag to create multiple datepickers, each with a different ID. at the moment it does nothing though, and the console does not show any erros. does anyone know why? and what I can do to fix it? I would prefer to have a solution in javascript, but jquery is also good.
in addition to @bipen’s response, you should probably not use the $(function(){…}); inside your function: