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?
+1
A:
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();
Brock Adams
2010-10-07 01:08:58
Ah. That worked. Any ideas on how you'd stop the enter key from submitting the form?
Joren
2010-10-07 01:24:09
@Joren: Open a new question for that and post details. In general you would change how you bind the event handler and/or use `event.preventDefault();`, `event.stopPropagation();`, and `return false;` in a/the appropriate event handler.
Brock Adams
2010-10-07 01:40:48
A:
You can trigger the onchange "really":
From within GM:
unsafeWindow.dropdownObject.onchange();
From the webpage:
dropdownObject.onchange();
Dr.Molle
2010-10-07 01:38:16