Question

I'm writing a greasemonkey script that creates an auto-complete search type box which makes it easier to select from a large dropdown on a webpage. The dropdown has inline onchange code which I can't seem to get to trigger when I change the selection using javascript. Any ideas?

Was it helpful?

Solution

Suppose the the page had something like:

<input onchange="someFunction()">

Then your Greasemonkey JavaScript could change the input value and then call the function using:

unsafeWindow.someFunction();

OTHER TIPS

You can trigger the onchange "really":

From within GM:

unsafeWindow.dropdownObject.onchange();

From the webpage:

dropdownObject.onchange();

For tampermonkey, this works simply without using unsafewindow.

Suppose the dropdownbox is defined in webpage something like:

<select id="dd_id", onchange="myfunction()">

Then following code in userscript triggers the onchange event:

document.getElementById('dd_id').onchange();

Also, it is suggested to avoid use of unsafewindow in documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top