Attach single calendar to form

Hello all,
I was wondering if someone could help me on how to attach a single calendar to an input on the form. I was reading the other topic on how to attach a double, but it wasnt working. I kept getting an error in my browser saying that “object missing in calendar.js”.

<a onclick="filter()">click me</a>

The code

<script>
var dhxWins, w1, dhxList;
function filter() {
    var formData = [
        {type: "input", id: "datefrom", label: "Select a date"},
        {type: "button", name: "submit", value: "Filter"}
    ];
    dhxWins = new dhtmlXWindows();
    x = (document.body.clientWidth/2)-(400/2);
    y = (document.body.clientHeight/2)-(520/2);
    w1 = dhxWins.createWindow("w1", x, y, 400, 520);
    w1.button("close").enable();
    w1.setText("Filter Criteria");
    dhxList = w1.attachForm(formData);
    dhxList.setSkin("dhx_black");
}

Thanks for any help.

Hello,

Please see attached demo.
26.zip (57.1 KB)

I appoligize for this,
but can anyone post the coding. Im in afghanistan and i cant download it because of our network administrators. Thanks

f0b0s

Sure

[code]

Demo
[/code]

The above example works only for one html input element. When a second html input element is added to the form.The calendar works only for one input element. The one which was activated as first.

[code]




var form, myCalendar;
function doOnLoad() {
		var formData = [
			{type: "input", name: "calendar1", label: "Date2"},
			{type: "input", name: "calendar", label: "Date"},
			{type: "button", name: "btn", value: "Submit"}
		];
		form = new dhtmlXForm("listObj", formData);
		
		dhtmlXForm.prototype.items.input.showCalendar = function(item) {
			var inp = item.childNodes[0].childNodes[1].childNodes[0];
			inp.onclick = function(e){
				e = e||event;
				e.cancelBubble = true;
				e.returnValue = false;
				if (!myCalendar) {
					myCalendar = new dhtmlXCalendarObject(this, true);
					myCalendar.show();
				}

				return false;
			};
		};
		form.doWithItem("calendar", "showCalendar");
		form.doWithItem("calendar1", "showCalendar");
		
	}
	
</script>
[/code]

I have in my form multiple input element where I need to add a calendar. (Single calendar)

then you need separate intances

var myCalendar = {};

if (!myCalendar[this._idd]) {
myCalendar[this._idd] = new dhtmlXCalendarObject(…);
myCalendar[this._idd].show();

I just removed the if statement and callendar get recreated. This works also.

[code]inp.onclick = function(e){
e = e||event;
e.cancelBubble = true;
e.returnValue = false;
//if (!myCalendar) {
myCalendar = new dhtmlXCalendarObject(this, true);
myCalendar.setDateFormat("%d.%m.%Y");
myCalendar.show();
//}

				return false;
			};[/code]

Yes, but it not good create every time new instance.

Why ?