Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OOP Javascript Event

    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
    Last edited by kaliopi; 08-28-2006 at 10:12 PM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •