[thelist] JS: DOM generated page, IE & setAttribute() = failure

Christian Heilmann codepo8 at gmail.com
Wed Jun 27 01:25:57 CDT 2007


>         iptYear.setAttribute("onClick","clearField(this);")

Actually that makes sense that it fails. onclick is an event handler,
not an attribute. if you use

iptYear.onclick = function(){clearField(this);}

instead it'll work. If you use onclick in your HTML you mix structure
and behaviour which is not a clever plan in terms of maintenance.

More: http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html

-- 
Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/



More information about the thelist mailing list