Referencing a YUI object from an event handler

by timvasil 10/30/2007 3:19:00 PM

I'm just getting started with the YUI JavaScript framework.  My first task was to wrap YUI TabView control with an ASP.NET control so I could easily design and manage it from the server side.  Part of this task involved tracking the selected tab. 

It's easy enough to hook the appropriate event:

new YAHOO.widget.TabView('id').addListener('activeTabChanged', tabViewChangeHandler);

But how do I, from the handler, get a reference to the YUI TabView object?  I need a reference to the object so I can get its ID and the set a hidden field to record the currently selected tab.

As it turns out, the this keyword conveniently enough references the TabView object within event handler functions.  Cool!  So recording the selected tab in a hidden field is pretty easy:

tabViewTabChangeHandler : function(oEvent)
{
    var sTabViewId = this.get('element').id;
   
var sTabId = oEvent.newValue.get('contentEl').id;
   
var oTabIdField = YAHOO.util.Dom.get(sTabViewId + "_sel");
   
oTabIdField.value = sTabId;
}

 

Tags: ,

ASP.NET

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Search

Calendar

«  May 2012  »
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Recent comments

Archive