Calendar attachobject


I have two text boxes on a screen. I initialize the calendar with the first text box and then in the onclick event of the second text box , I use the attachobject method of the calendar to attach the calendar to the second text box. How ever this throws the following error:

Error: this.i[a].addEventListener is not a function
Source File:…/dhtmlxcalendar.js
Line: 1341

The problem is replicated in the following example:

How to make the same calendar work with several input text boxes. Please help.

Sravanthi Sontha

When initializing the calendar, you can attach it to several inputs. For example :

var calendar = new dhtmlXCalendarObject(['input1', 'input2']);


My textboxes are dynamically created, hence I would not be able to do what you have suggested. How to make it work with attachObject?

Thanks ,
Sravanthi Sontha

I have the same problem with version 3.0

Previously, I used v2.1 and it works fine (e.g. 1 calendar for multiple input without the need to attach object ).

I also have my input field dynamically generated.

Please help


Any help would be appreciated.



There is setParent method that attaches calendar to another div. However, it won’t apply features that are actual when you attaches calendar to several inputs.


Also you may use setPosition method which displays calendar in a certain top and left position. Here are the post with the latest libraries attached:
Please use them

Hi ,

I have used the set parent and it is working, but as you said it won’t apply features that are actual when you attaches calendar to several inputs. I need to access the date returned and put it back into my text back. How can I access its parent? I have tried one of your suggestions in your previous post
var id = (typeof calendar.contId != ‘string’?;
But it is throwing an error - " contid is undefined "
Is there a way we can make the attachobject function work?

Thanks ,


Calendar doesn’t support attachObject method. You can either attach calendar to several inputs or create a simple calendar with div as a parent container. In the latter case, you may use setPosition method to show calendar in different positions.


How is it possible to attach a calendar to several inputs when the inputs are dynamically loaded?


If you want to use automatic attaching to inputs, you may unload the existent calendar and then create it for another set of inputs:

myCalendar = new dhtmlXCalendarObject([“input1”]);
/to add more inputs/
myCalendar = new dhtmlXCalendarObject([“input1”,“input2”,“input3”]);


calendar have functionality to be attached to/detached from inputs on the fly.

try this:


obj param should be object, not id or other text.

like this:

var newInp = document.createElement("INPUT"); newInp.type = "text"; document.body.appendChild(newInp); myCalendar.attachObj(newInp);