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

Frank lists at frankmarion.com
Wed Jun 27 00:50:35 CDT 2007

I've used DOM to programmatically build a chunk of page (several 
paragraphs, a form and some fields). The fields have error checking 
that when a user inputs something out of range pops up an error 
message and changes the backgroundColor of the field to red.

The following works correctly in FF, Opera and Safari


I know setAttribute() is borked on IE (based on my 
research).  Considering that the whole chunk of document is 
programmatically generated, how can I add an onclick event to a field 
that will both correctly trigger a function and pass it it's id? (so 
that clearField(obj) can reset the style and edit the value)

Sample (of simplified) code below

         // HTML structure: INPUT. Year input.
         iptYear = document.createElement("input");

         // Some of the multiple variations that fail...
         // iptYear.setAttribute('"onclick", "clearField(this)");
         //iptYear.onclick = 

         f.appendChild(iptYear); // (f is the form)

You can see it at work here:

Try entering 2008 in the year field...


Frank Marion     lists at frankmarion.com      Keep the signal high.

More information about the thelist mailing list