How to access and run field events from extension js?

Posted by Dan Roberts on Stack Overflow See other posts from Stack Overflow or by Dan Roberts
Published on 2010-03-15T19:26:46Z Indexed on 2010/03/15 19:29 UTC
Read the original article Hit count: 310

I have an extension that helps in submitting forms automatically for a process at work. We are running into a problem with dual select boxes where one option is selected and then that selection changes another field's options. Since setting an option selected property to true doesn't trigger the field's onchange event I am trying to do so through code.

The problem I've run into is that if I try to access or run functions on the field object from the extension, I get the error

Error: uncaught exception: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: chrome://webformsidebar/content/webformsidebar.js :: WebFormSidebar_FillProcess :: line 499" data: no]

the line causing the error is...

if (typeof thisField.onchange === 'function')

The line right before it works just fine...

thisField.options[t].selected=true;

...so I'm not sure why this is resulting in such an error.

What surprises me most I guess is that checking for the existence of the function leads to an error.

It feels like the problem is related to the code running in the context of the extension instead of the browser window document. If so, is there any way to call a function in the browser window context instead? Do I need to actually inject code into the page somehow? Any other ideas? Thanks

© Stack Overflow or respective owner

Related posts about firefox-addon

Related posts about firefox-extension