W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2007

event for attribute change of a <select> (DOMAttrModified?)

From: Fulvio <www-dom@svsoliton.net>
Date: Mon, 8 Jan 2007 10:28:47 -0800 (PST)
Message-ID: <4420.>
To: www-dom@w3.org

Say you have a <select>, that gets disabled and enabled by some event,
i.e. the "disabled" attribute gets set or removed.  Is there any event
that I could trap when the disabled state changes?

The only two I could find are:
- onpropertychange, which is only supported in IE, and only when the
"disabled" attribute gets removed, not when it is set
- DOMAttrModified, which is in the Level 2 DOM spec
but somehow does not work right in Firefox:  I do get a flurry of 15 
events when the page loads, 6 of which seem to be triggered by the
"disabled" attribute for the "scrollbar" of the select, but never when it
actually gets disabled or enabled.

Here is a small sample: (the console.log works if you have Firebug

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>dynamic filters</title>

<script type="text/javascript">
function selectchange(select) {
  var child = document.getElementById(dynfilterhierarchy[1]);
  var foo = child.getAttribute("disabled");
  if (foo) { child.removeAttribute("disabled", 0); }
  else { child.setAttribute("disabled", "true", 0); }

function selectpropertychange(e) {
//  console.log("event: %o, target: %s, name: %s, oldvalue: %s,
newvalue: %s, change: %s, relatednode: %o", e, e.target.id, e.attrName,
e.prevValue, e.newValue, e.attrChange, e.relatedNode);
  alert("hello, world!");
<select id="dynfilter0" onchange="selectchange(this);">
<option> </option>
<select id="dynfilter1" onpropertychange="selectpropertychange();">
<select disabled="disabled" id="dynfilter2">

<script type="text/javascript">
  var dynfilterhierarchy = new Array("dynfilter0", "dynfilter1",
  var node = document.getElementById(dynfilterhierarchy[1]);
  node.addEventListener('DOMAttrModified', selectpropertychange, false);
Received on Tuesday, 9 January 2007 02:51:28 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:13 UTC