Access Date from Calendar inside Form inside Layout

I have a layout. In cell “a” I have attached a calendar inside a form. I would like to have an OnClick event that reloads data in a grid attached to cell “b”. How do I access the calendar object from cell “b”? Specifically looking for the date as this will reload new data for the grid with the selected date?

How do I access the calendar object from cell “b”?

is grid is inside an iframe? if it is not, calendar can be accessed the same way as it would be done without layout.

If you are using dhtmlxForm with calendar item, calendar object can be got by getCalendar(itemName) method:

[code]var calendar = dhxForm.getCalendar(“calendarName”);

Specifically looking for the date as this will reload new data for the grid with the selected date?

calendar.attachEvent(“onClick”,function(date){
var d = calendar.getFormatedDate("%Y-%m-%d",date); /or var d = date.valueOf()/
grid.clearAll();
grid.load(url+"?date="+d);
})[/code]

Thanks, Alexandra,

What is the best way to display the calendar in a layout? I want the calendar to be visible in one cell of the layout and on click update a grid in another.

Currently I have the following:

planning.php

                calForm = layout.cells("a").attachURL("loadcal.htm");    
                PlanGrid = layout.cells("b").attachGrid();

layout.htm

[code]

[/code]

And back in planning.php

        CalFrame=layout.cells("a").getFrame();
        myCal=CalFrame.contentWindow.myCalendar;
            myCal.attachEvent("onClick",function(){
                alert(myCal.getFormatedDate("%Y-%m-%d",myCal.getDate()));
            })

My problem is now that the above code only works on a toolbar button. The calendar is the last to load, so if I use this anywhere else it gives me an error saying myCal is null or not an object. So I don’t have the onClick event.

In this case, the suggestion you gave doesn’t work, but it seems so simple.

What would you suggest is the best way to set this up?

Thanks for your help.

You need to add a code that will call the code of parent window. It should be added in loadcal.htm (layout.htm page). There are two ways:

  1. loadcal.htm:

planning.php:

function setCalEvent(){
CalFrame=layout.cells(“a”).getFrame();
myCal=CalFrame.contentWindow.myCalendar;
myCal.attachEvent(“onClick”,function(){
alert(myCal.getFormatedDate("%Y-%m-%d",myCal.getDate()));
})
}

  1. or

loadcal.htm:

myCalendar.attachEvent(“onClick”,function(){
parent.onCalClick(myCalendar.getFormatedDate("%Y-%m-%d",myCalendar.getDate()));
})

planning.php:

function onCalClick(date){

}

Thanks, Alexandra.

I used the 1st option and it works perfectly.