Datepicker popup not working in a javascript form?

Datepicker popup not working in a javascript form?

I have a JavaScript function with a form in it, in this form is a input with the id datepicker but theres no datepicker popup.

The datepicker is working outside the java script form, in the regular html code.

Is there a way to get a popup of the datepicker in the form in the java script?