dragan Posted June 27, 2013 Share Posted June 27, 2013 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 More sharing options...
Moderators big_daddy Posted June 27, 2013 Moderators Share Posted June 27, 2013 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() Link to comment Share on other sites More sharing options...
dragan Posted June 27, 2013 Author Share Posted June 27, 2013 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 More sharing options...
Moderators big_daddy Posted June 28, 2013 Moderators Share Posted June 28, 2013 (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 June 28, 2013 by big_daddy Link to comment Share on other sites More sharing options...
dragan Posted June 28, 2013 Author Share Posted June 28, 2013 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 More sharing options...
Moderators Solution big_daddy Posted June 28, 2013 Moderators Solution Share Posted June 28, 2013 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) mexykanu 1 Link to comment Share on other sites More sharing options...
dragan Posted June 28, 2013 Author Share Posted June 28, 2013 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 More sharing options...
Moderators big_daddy Posted June 28, 2013 Moderators Share Posted June 28, 2013 You're welcome. This will be one to bookmark as I suspect it will come up again. Link to comment Share on other sites More sharing options...
afried101 Posted March 6, 2014 Share Posted March 6, 2014 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 More sharing options...
mexykanu Posted August 22, 2014 Share Posted August 22, 2014 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now