Thomas wrote:
[color=blue]
> Hi,
>
> I'm having a problem with the dynamically created inputfields in
> Internet Explorer.
> The situation is the following:
> - I have a dynamically created table with a textbox in each Cell.
> - It is possible to Add and Delete rows
> - Some cells have special attributes (readonly and events)[/color]
[snip][color=blue]
> CellPostcodeTekst.setAttribute("onblur","call_zoek gemeente_byID(\''p_plaats_sys_vest"[/color]
[snip][color=blue]
> CellgemeenteTekst.setAttribute("READONLY","true");[/color]
[snip]
[color=blue]
> Now The problem(s) is this:
> If you change the textbox "p_postcode" (which is postal code in
> english - or something like that) it must invoke a function which
> looks up the correct city.
> This works fine in Firefox but it doesn't do a damn thing in Internet
> Explorer 6. I've allready changed the onchange event to onblur but
> that doesn't help.[/color]
The problem is that event handler attributes are functions, not strings.
Mozilla browsers parse the string and create a function object, just like
they do when they parse the HTML. IE, on the other hand, expects you to
set the attribute to a Function object; it doesn't parse the string.
Which is correct? Neither, really. According to the W3C DOM specs, the
setAttribute method only accepts a string for the second argument, so
IE isn't compliant. On the other hand, event handlers are special cases
that are handled by a completely separate method using DOM-compliant
clients; they aren't really attributes (which can only be strings) at all.
"addEventListener"
http://www.w3.org/TR/DOM-Level-2-Eve...dEventListener
Unfortunately, IE doesn't follow the spec for adding event handlers to
elements (of course); it has its own proprietary method.
"attachEvent Method"
http://msdn.microsoft.com/workshop/a...ttachevent.asp
Unless you want to do client capability-sniffing, the cross-browser way
to add event handlers to elements is to avoid the setAttribute menthod
(which is the wrong approach anyway) and the W3C-DOM and MS-proprietary
methods and to use the DOM-0 format:
CellPostcodeTekst.onblur=function(){call_zoekgemee nte_byID(...)}
[color=blue]
> Second problem is the readonly attribute which doesn't seem to work in
> IE.[/color]
IE wants the attribute to be spelled "readOnly" (with a capital O).
You should also be aware that although Mozilla accepts the value
"READONLY", Opera does not. It also expects the value "readOnly".
[color=blue]
> Now my question is offcourse: Why doesn't it work in Internet
> Explorer? Am I dealing with a MS bug here or is there some other
> explanation?[/color]
setAttribute isn't really meant to handle event handlers.
[color=blue]
> Strange thing is that a lot of other attributes work perfectly (but i
> don't need those, haha, programming is fun) like disabled, style,
> etc....[/color]
Other attributes are string values; setAttribute is meant to work with
them.
[color=blue]
> I's nearly impossible to change the whole code (time is running out)
> so I'll have to find a fix here!
>
> anyone have a clue?[/color]
Use the DOM-0 method to attach event handlers and use the value
"readOnly" to set the readonly attribute.
--
Steve
If a man points at the moon, an idiot will look at the finger.
-Sufi wisdom