IE, getAttribute, search, and selects
Philip Thompson <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
I'm racking my brain over this one. IE is being mean again. I am
getting the errors "Object doesn't support this property or method"
and "Could not complete the operation due to error 80020101." I did
searches for these, but none of those specific problems seemed to
apply to me. Here's my (condensed) JS - what's wrong?!
<js>
function updateRequiredField (id) {
var element = document.getElementById(id);
var onchange = element.getAttribute('onchange');
var action = "updateRequiredField('"+id+"');";
...
if (element && element.options) {
// If a select box
if (onchange) {
alert(element.name+' onchange: '+onchange);
if (onchange.search('updateRequiredField') == -1) {
onchange = onchange ? onchange + action : action;
element.setAttribute('onchange', onchange);
}
} else if (!onchange) {
element.setAttribute('onchange', action);
}
}
...
}
</js>
IE breaks on line 11 - "if (onchange.search...". When alert'ing the
onchange string in IE, I get: "function anonymous()
{ aFunctionName(); }". In FF, I get: "aFunctionName();" and it works
fine. Where is that "function anonymous" coming from?
What I'm wanting to do is dynamically add an onchange event. This
event function will then run validation on the form field. Any helpful
hints on what's happening would be greatly appreciated!
Thanks,
~Philip