Question

I'm using pyjd/hulahop/pyxpcom to load a HTML document with an input field, this input field is bound with "onchange=...." to some JS function doing some AJAX call.

The html looks like this:

...
<input name="inp" type="text" onchange="checkInput()"></input>
...

I can easily locate and modify the input field with this code:

import pyjd
pyjd.setup(URL)
bw = pyjd.hula.wv
doc = bw.getDomDocument()

inp = doc.getElementsByName("inp").item(0)
inp.value = "somestring"

However, that doesn't trigger the "onchange" handler, it seems I have to manually tab into/out of the input field to do so. From what I've seen the pyxpcom interface is pretty close to the C++ one, thats why I read a bunch of C++ snippets out there, I tried a couple of things using the FocusManager interface, issuing .focus() and .blur() events on the "inp" element, but no success so far.

Does somebody know how this is supposed to work? Is it even possible? Is there some way to call the attached onchange handler directly?

P.S.: Sorry for the pyjamas tag, I'm not allowed to create a 'pyjd' tag :-)

Was it helpful?

Solution

Change events are normally sent when the field loses focus or the Enter key is pressed, and it isn't expected that scripted changes will fire them, so it is best to fire your own change event if that's what you need to happen. There is some sample code for dispatching a click event; the procedure for a change event is similar but in that case the event type is Events instead of MouseEvents and you therefore need to call InitEvent instead.

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