Sign in to follow this  
Followers 0
dragan

_IEFormElementOptionSelect doesn't trigger the onchange function in IE9+

10 posts in this topic

Has anyone found a solution to this:

I'm trying to use _IEFormElementOptionSelect to change the "select" option on the webpage, but it's not working.

It's changing the value, but not triggering the onchange event.

I've tried in IE8 and lower and it works, but it doesn't work on IE9 and above. I have also tried to use the _IEAction with "focus" on the element before calling IEFormElementOptionSelect, and I still haven't got the results from the onchange event (the select switches to desired option, but doesn't trigger any event).

So I was thinking, is there a way to call the function manually?
The function name is:

bookingChanged_Rev1()

...this is the full element:

<select name="sortOrder" id="sortOrder" class="srtOrder  no_cpu " onchange="bookingChanged_Rev1()">
<option value="popularity" selected="selected">Ranking</option>
<option value="alphabetical">Name</option>
<option value="priceHigh">Price (high to low)</option>
<option value="priceLow">Price (low to high)</option>
</select>

so I was thinking of calling something like:

$oIE.document.parentwindow.eval('bookingChanged_Rev1();')

right after I change the "select" via IEFormElementOptionSelect but that just opens another IE window.
I also tried to submit the form with _IEFormSubmit on the form where this element is, but still no luck.

Has anyone ever had to deal with this issue? Has this been solved already? I haven't found any solution...

Share this post


Link to post
Share on other sites



onchange event - Note the following line "The onchange event does not fire when the selected option of the select object is changed programmatically."

Get reference to the appropriate option and fire the event manually.

$o_Option.onchange()

Share this post


Link to post
Share on other sites

I missed that, but tnx for pointing that out.

I have tried:

...
;I tried with this enabled/disabled
;_IEAction($oSelect, "focus")
;_IEFormElementOptionSelect($oSelect, $selIndex, 1, 'byIndex', 1)
Local $oItems = $oSelect.options
Local $oItem = $oItems.item($selIndex)
If NOT $oItem.selected then
    $oItem.onchange()
    ;and I tried this:
    ;$oItem.fireEvent("onChange")
EndIf
...

..but the event was still not triggered.
I tried by finding the option object with this method:

...
Local $oOptionAll = _IETagNameGetCollection($oSelect, 'option')
For $oOption in $oOptionAll
    If $oOption.value == $value_i_want_to_change then $oOption.onchange()
Next
...

I get the option's object, but the onchange event is still not triggered.
Am I missing something?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I forgot that _IEFormElementOptionSelect fires the onchange and onclick events for you by default. You may need to take a look at the bookingChanged_Rev1() function to see if there are further checks. If you don't see anything obvious go ahead and post the function code so we can review it.

Edited by big_daddy

Share this post


Link to post
Share on other sites

Yeah, the _IEFormElementOptionSelect does seem to have the onclick and onchange events trigered. But the strange thing is why does it fire the event in older IE, and not in the newer? Why do I have to switch to IE8 "document mode" in order to be able to fire up the onclick, onchange events?

Anyway, this is the function:

var bookingChanged_Rev1=function()
{
    var a=$("SORT_FORM").sortOrder;
    var c=$("BOOKING_FORM")&&$("BOOKING_FORM").sortGroup.checked;
    var b=_newBookingSortValue(c,a.value);
    updateList(null,b,ACTION_FILTERCHANGED)
}

If I could call this function from autoit that would be perfect. So can it be done? Can this function be called from autoit?
I tried:

$oIE.document.parentwindow.execscript(.....
;and
$oIE.document.parentwindow.eval(.....

but both are starting a new IE instead of calling this function.

I can paste the _newBookingSortValue function too:

var _newBookingSortValue=function(b,c)
{
    var a=c;
    a=a.replace(/be_/,"");
    if(b)
    {
        a="be_"+a
    }
    return a
}

..but I cannot paste the updateList one as it's enormous! And I wouldn't bother you with it since it would take ages to read it.

Share this post


Link to post
Share on other sites

I think this guy ran into the same issue. Luckily for us he also found a solution. Try something like this:

$oEvt = $oIE.document.createEvent("HTMLEvents")
$oEvt.initEvent("change", True, False)
$oSelect.dispatchEvent($oEvt)
1 person likes this

Share this post


Link to post
Share on other sites

That worked!
 

Func _SilentEvent($o_Object, $o__IE, $__the_event = "click")
    If NOT IsObj($o__IE) then Return SetError(1)
    ;disable "IE click" sound
    Local $sDefault = RegRead("HKEY_CURRENT_USER\AppEvents\Schemes\Apps\Explorer\Navigating\.Current", "")
    RegWrite("HKEY_CURRENT_USER\AppEvents\Schemes\Apps\Explorer\Navigating\.Current", "", "REG_EXPAND_SZ", "")
    Local $o_Evt = $o__IE.document.createEvent("HTMLEvents")
    $o_Evt.initEvent($__the_event, True, False)
    $o_Object.dispatchEvent($o_Evt)
    ;re-enable "IE click" sound
    RegWrite("HKEY_CURRENT_USER\AppEvents\Schemes\Apps\Explorer\Navigating\.Current", "", "REG_EXPAND_SZ", $sDefault)
    Return 1
EndFunc   ;==>_SilentClick

This is really usefull as I had this problem before, but now I can fire up any event. I tried this with "click" event and it works too.

Thank you.

Share this post


Link to post
Share on other sites

You're welcome. This will be one to bookmark as I suspect it will come up again.

Share this post


Link to post
Share on other sites

I understand this is a solved post, but I had an extremely similar issue that this post did not solve.  Posting so it may help someone else that comes across this post (as I did) and the above solution doesn't work .  Basically there was a hidden input and the OptionsSelect box.  Setting only 1 value didn't fire the event.  Setting both did.  Just had to View Source and look around for it.

$searchBox = _IEGetObjById($oie,"searchMethod")
_IEFormElementOptionSelect($searchBox,"3",1,"byValue",1)
$oHidden = _IEGetObjById($oie,'EligibilityQuery_1{actionForm.searchMethod}')
$oHidden.value = 3

Again, just in case it can help someone else out in the future.

Share this post


Link to post
Share on other sites

 

I think this guy ran into the same issue. Luckily for us he also found a solution. Try something like this:

$oEvt = $oIE.document.createEvent("HTMLEvents")
$oEvt.initEvent("change", True, False)
$oSelect.dispatchEvent($oEvt)

This helped me as well. Thank you for sharing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0