Jump to content

_IEFormElementOptionSelect doesn't trigger the onchange function in IE9+


Go to solution Solved by big_daddy,

Recommended Posts

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...

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

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
Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 8 months later...

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.

Link to comment
Share on other sites

  • 5 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...