Re: IE, getAttribute, search, and selects
Philip Thompson <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
On Mar 4, 2008, at 6:47 PM, Tony Mechelynck wrote:
> Philip Thompson wrote:
>> 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
>
> There is no mention of <js> in my HTML reference. Is it synonymous to
> <script type="javascript"> ? Or did I misinterpret you?
>
> Oh, and by the way, maybe a Microsoft newsgroup (
> nntp://msnews.microsoft.com/* IIRC) or a general Usenet group about
> javascript, would be better suited for this question.
Sorry, the <js> was just for this example. I use <script type="text/
javascript">. =D
I wasn't sure whether this would be a problem for the 'dom' group, so
I also sent it to the 'dev-tech-javascript' group. No response from
them yet. =/ Alas, I will see what I can do.
Thanks for the input!
~Philip