Jump to content

add object events


aspnetguy

Recommended Posts

So I want to assign a onchage event to my object, i tried this

var SelectBox = new DropDownList(document.getElementById('selectList'));function DropDownList(obj){    this.Items = obj.options;    ...    this.onchange = function(){}}

but it thinks I am trying to create a onchange method for the object.so I tried this

var SelectBox = new DropDownList(document.getElementById('selectList'));function DropDownList(obj){    this.Items = obj.options;    ...    obj.onchange = function(){this.SelectedIndex = obj.selectedIndex}}

But in this context (inside the onchange function) this is refering to the obj because I am defining the onchange for obj and obj (select tag) does not have SelectedIndexIs there a way to attach an onchange event (or an event for that matter) to the object (this.onchange)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...