I've got a drop down on a page that I'd like to add an onChange event to it programatically, but can't seem to get it to work. I'm adding the dropDown and the onChange handler to the dom dynamically
Relavent Javascript code looks like this:
Dropdown get's created ok, but the onchange event never fires... Any ideas?
Relavent Javascript code looks like this:
Code:
createDropDown: function (dataCollection, dropDownId, cssClass, onChangeFunction)
{
// Remove existing list with this Id, if exists
var listTag = $g(dropDownId);
if (listTag) this.parentDiv.removeChild(listTag);
// Create list
var list;
list = $c('select');
list.id = dropDownId;
list.name = dropDownId;
if (onChangeFunction)
{
list.onchange = onChangeFunction;
var onChangeHandler = new Function(list.onchange);
if (list.addEventListener) {
list.addEventListener('onchange', function() {eval(onChangeFunction)}, false);
} else if (list.attachEvent) {
list.attachEvent('onchange', onChangeHandler);
}
}
if (cssClass != '')
{
this.setCssClass(list, cssClass);
}
// Add items to list
var option;
for(index in dataCollection)
{
var item = dataCollection[index];
option = $c('option');
var value = item.Value;
var max = 255;
var title = item.Text;
if (title.length > max)
title = title.substring(0, max) + '...';
option.setAttribute('value', value);
option.innerHTML = title;
list.appendChild(option);
}
return list;
}
Dropdown get's created ok, but the onchange event never fires... Any ideas?