...

View Full Version : OOP Javascript Event



kaliopi
08-28-2006, 09:05 PM
Hi,

Im trying to attach to my Objects.

I have made a few classes that inherit from a base class. In the child class i have a few divs, and a table element with values in multiple td's.

I would like to attach a mouseover event to this however im not doing something right.

This is the way im attaching the event. The statement below is found in the for loop of the DrawCalendar member function. I think that passing self as a parameter actually passes the Function since it is the current object?

anyhow self should actually be passing the <td> element created so that i can get the id of the <td> and do further things with it.

cal_cell.onclick = function(e) { return self.CalClickEvent.call(self); }

This method invokes fine, but the parameter is messed giving an undefined value when i alert or e has no properties other times.

Here is a snippet of what my code looks like.

Calendar = function(id, width, height, posX, posY, footer, moveable, bgcolor, day, month, year, font, e){
//Get Today's Date
...
...
//Create our window handler Base Class
this.wndHandle = new Window(id, width, height, posX, posY, false, true, bgcolor, font);
this.CreateCalendar();

//Display our window with the added calendar component.
this.wndHandle.Display();
}

Calendar.prototype =
{
CreateCalendar : function(){
this.DrawCalendar();
},

DrawCalendar : function(){
var self = this;
this.calendar = document.createElement("div");
this.calendar.head = document.createElement("div");
this.calendar_body = document.createElement("table");
this.InitMonth(self);
this.InitYear(self);
this.calendar.appendChild(this.calendar.head);

var cal_head = document.createElement("tr");
var date_index = 1;
idx = 0;

//Create Days in Month
for( i = 0; i < 6; i++){
var cal_row = document.createElement("tr");
for(j = 0; j < 7; j++){
var cal_cell = document.createElement("td");
if(idx++ >= this.begin_day && date_index <= month_days[this.month]){
cal_cell.id = "day_" + date_index;
cal_cell.appendChild(document.createTextNode(date_index++));
cal_cell.onclick = function(e) { return self.CalClickEvent.call(self); }
}else{
//cal_cell.("class", "day_off");
}
cal_row.appendChild(cal_cell);
cal_cell = null;
}
this.calendar_body.appendChild(cal_row);
cal_row = null;
}
this.calendar.appendChild(this.calendar_body);
this.wndHandle.element.appendChild(this.calendar);
},


help pls and thanks

A1ien51
08-29-2006, 02:53 AM
My brain is not functioning, but try:

cal_cell.onclick = function(e) { return self.CalClickEvent.call(self,e); }

or

var ref = this;
cal_cell.onclick = function(e) { return ref.CalClickEvent(e); }

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum