IE and OnChange

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

IE and OnChange

25 May 2015, 20:18

I'm automating a form that we use at work. It has a series of drop down menus in the webpage, where the next DDL contents is generated based on the selection you make on the prior DDL.

I was using

Code: Select all

wb.Document.All.category.fireEvent("onchange",0)
to launch the onchange event.

However now when I look at the HTML there is no onchange. My script doesn't work, but if I manually make the selections it works fine. Here is an excerpt of the html:

Code: Select all

<td width='35%' valign='top'>
              
                      <select name="category" style="width: 85%;" class="formStyle" id="CATEGORYID"><option value="0">-- Select Category --</option> 
                              <option value="2402">Business</option> 
                              <option value="1803">Cell Phone</option> 
                              <option value="903">Convention</option> 
                              <option value="3001">Guest Internet</option> 
                              <option value="2">Hardware</option> 
                              <option value="3601">Hardware Request</option> 
                              <option value="1801">Inventory</option> 
                              <option value="3301">NAF</option> 
                              <option value="10">Network</option> 
                              <option value="3603">Network Request</option> 
                              <option value="11">Operating System</option> 
                              <option value="6">Printers</option> 
                              <option value="2401">Server</option> 
                              <option value="3">Software</option> 
                              <option value="3602">Software Request</option> 
                              <option value="5">Switches</option> 
                              <option value="9">Telephone</option> 
                              <option value="2702">Wireless</option></select> <script> catValue  = 'null' </script> 
            </td>
I'm not very good with HTML at all, so I don't know what's causing the second DDL to generate it's list anymore. My boss says he isn't aware of any changes to the website, but I'm either insane/misremembering/etc or there must have been. I'm 100% positive I used to see an onchange in there.

So two fold question, how do I proceed and why does it work normally? What's causing "subcategory" to get updated and populate a list when I choose something in "category"?
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: IE and OnChange

26 May 2015, 00:40

If has worked before, something most have changed

How long has it not been working now?

There meny ways that the page maker can use to check for an event in a dropdown some of the one's i have see are onchange, onfocus, onblur, onkeydown, eventlisners, all kinds of Ajax scripts or other scripted setups.

So without knowing more about your page it can be hard to tell whats going on...
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: IE and OnChange

26 May 2015, 03:06

Blackholyman wrote:If has worked before, something most have changed
Yes, this:
gilliduck wrote:However now when I look at the HTML there is no onchange.
I misread it (as "there is no change") the first time I saw the post.

I'd suggest looking in any other scripts which are loaded by the page. There has to be a script implementing that behaviour.

You can search each script for CATEGORYID, since that is what it would be using to identify the control (to hook up the event handlers).
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: IE and OnChange

26 May 2015, 13:22

Doing a little further searching I do find a <Script> that mentions the categoryid:

Code: Select all

<script>
  var cat = $("CATEGORYID");
  var sct = $("SUBCATEGORYID");
  var itm = $('ITEMID');
  var grp = $('GROUPID');
  var tch = $('TECHNICIANID');
  var site = $('siteID');
  //console.debug("cat val :%s   subcatval : %s", cat.value,sCatValue);
  invokeCSIPopulation(cat, sct, itm, sCatValue, itemValue, catValue);

  var svalue = null;
  if(site) { svalue = site.value; }
  invokeSGTPopulation(site, grp, tch, techValue, grpValue, svalue);


  if($('IMPACTID') && $('URGENCYID') && $('PRIORITYID')) {
    Event.observe("IMPACTID", 'change', function() { populatePriorityMatrix(true, false); });
    Event.observe("URGENCYID", 'change', function() { populatePriorityMatrix(true, false); });
  }
  populatePriorityMatrix(true, false);
  //SD-13310  assets for requester not populated when we came from quick create page.
  getUserAssets('reqSearch', 'workstationID','requesterID');
</script>
I do see at the end of the section that I previously posted there is a

Code: Select all

<script> catValue  = 'null' </script> 
. I'm not sure how to iniatate this though. Thoughts? Or should I be looking for something else in the HTML?
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: IE and OnChange

27 May 2015, 01:02

So it uses $("CATEGORYID") to select that element into cat - using a framework like Prototype, not jQuery since that would use $("#CATEGORYID"). It then passes cat to invokeCSIPopulation(cat, ...). It probably does the event hookup in that function.

(Edited a few times within 20 minutes of posting):

Are you actually changing the value before trying to fire the event? If not, I don't see how it could have ever worked. fireEvent's second parameter is supposed to be an event object, but you're passing 0.

I had a suspicion that fireEvent() was an IE-specific thing, so looked it up. MSDN doesn't say, but I think it won't work in the more recent, more standards-compatible versions of IE. Apparently you should use dispatchEvent instead in IE9 and later.
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: IE and OnChange

07 Jun 2015, 16:18

To bring a dead topic back to life, I'm still without a clue.

I have 6 workstations that I run this script on, 5 of them are 32 bit, 1 is 64 bit. The 64 bit runs fine. The other 5 don't fully select the choice in the DDL.

Here is the full script:

Code: Select all

#SingleInstance, Force

Gui, Font, s14
Gui, Add, DDL, vSite, R01-International|R02-Universal|R03-Pointe Orlando|R04-Clarion|R05-Plaza|R06-Centre|R07-Shingle Creek
Gui, Add, Edit, vGuest_Name, Guest Name
Gui, Add, Edit, vRoom_Number, Room Number
Gui, Add, Button, gSubmit Default, Submit
Gui, Show
Return

GuiClose:
	ExitApp

Submit:
	Gui, Submit
	Sub1 := SubStr(Site, 1, 3)
	Subject := Sub1 . "-" . Room_Number . ": Guest Internet Issue"
	If (Site = "R01-International")
		Site := 5404
	If (Site = "R02-Universal")
		Site := 5405
	If (Site = "R03-Pointe Orlando")
		Site := 5406
	If (Site = "R04-Clarion")
		Site := 5407
	If (Site = "R05-Plaza")
		Site := 5408
	If (Site = "R06-Centre")
		Site := 5409
	If (Site = "R07-Shingle Creek")
		Site := 5410
	wb := ComObjCreate("InternetExplorer.Application")
	; wb.Visible := True
	wb.Navigate("https://mesd.mtg-fl.com/WOListView.do")
	Loading(wb)
	wb.Document.All.newadd.Click()
	Loading(wb)
	wb.Document.GetElementByID("__persistentAccountId__select").value := 5402
	wb.Document.GetElementByID("__persistentAccountId__select").fireEvent("onchange",0)
	Loading(wb)
	wb.Document.All.reqTemplate.value := 302
	wb.Document.All.reqTemplate.fireEvent("onchange", 0) 
	Loading(wb)
	wb.Document.All.reqName.value := "Guest"
	wb.Document.All.reqName.fireEvent("onblur")
	Loading(wb)
	wb.Document.All.UDF_CHAR1.value := Guest_Name
	wb.Document.All.UDF_CHAR2.value := Room_Number
	wb.Document.All.reqName.value := "Guest"
	wb.Document.All.category.value := 3001
	wb.Document.All.category.fireEvent("onchange",0) ;There is an issue here
	wb.Document.All.subCategory.value := 3002
	wb.Document.All.subCategory.fireEvent("onchange",0) ;and here
	wb.Document.All.item.value := 2402
	wb.Document.All.UDF_CHAR3.value := "Assist"
	wb.Document.All.siteID.value := Site
	wb.Document.All.level.value := 1
	wb.Document.All.title.value := Subject
	wb.Visible := True
	ExitApp
	

	
I've commented the two parts that are supposed to update the DDL. On the one 64 bit it works fine (in hindsight, it shouldn't since ther eis no "onchange" in the HTML for the thing that it's changing. The "Category" field shows the update, but doesn't pass the selection on to "subCategory". Therefore subCategory is empty until I change the contents of Category manually.

But what blows my mind is that it works FINE on the 64 bit system. Exact same IE, exact same script, exact same everything. Thoughts?
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: IE and OnChange

07 Jun 2015, 22:09

What does wb.Document.documentMode report on each system after the document is loaded?
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: IE and OnChange

08 Jun 2015, 15:23

Both report 11.000000
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: IE and OnChange

08 Jun 2015, 19:42

If you're still using fireEvent, try dispatchEvent instead. Although apparently fireEvent is working for you on one system, there are reports that it doesn't work on IE9+.
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: IE and OnChange

08 Jun 2015, 19:58

Error: 0x80020101 - Specifically: dispatchEvent

It doesn't seem to like that at all. Now granted all I did was replace fireEvent with dispatchEvent, so if there are additional tweaks (ie. what goes in the "()" after that, I didn't do anything, nor would I know where to start.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: IE and OnChange

08 Jun 2015, 22:17

You need to create and pass an event object. See the following pages for examples:
https://msdn.microsoft.com/en-us/library/ff975247
http://stackoverflow.com/questions/2856 ... t-manually
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: IE and OnChange

14 Jun 2015, 20:54

Lexikos, I'm not following what you mean but I was wondering if you could provide an example from this page HiFi. After setting the text, I put in the needle but it only highlights after I physically click in the input area.

Code: Select all

pwb := WBGet()
pwb.document.getElementByID("haystackPaneText").innerTEXT:="my haystack for test"
pwb.document.getElementByID("regex").Value :="\w*" 
pwb.document.getElementByID("regex").focus()


;************Pointer to Open IE Window******************
WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%

   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: IE and OnChange

14 Jun 2015, 21:24

As I said, there are examples on the pages I linked to.

If you change the value programmatically, you have to manually trigger the onchange event handler. gilliduck was already doing this using fireEvent, but it had stopped working. Your code does not event attempt to trigger the event.

I cannot test dispatchEvent at the moment as I do not have IE9+ on this PC.
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: IE and OnChange

15 Jun 2015, 08:37

Sorry if I was unclear. I know my code didn't try to attempt to trigger the event as I don't understand what is meant by that and I am unable to follow the examples on the pages. I was hoping someone could use this as an example so I could learn...
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: IE and OnChange

15 Jun 2015, 09:28

Ok I am despirately trying to figure out why you are passing '0' to IHTMLEventObj instead of just omitting this optional parameter
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: IE and OnChange

16 Jun 2015, 00:37

The first two examples on StackOverflow appear to be very simple. You just need the variable element to refer to your element (pwb.document.getElementByID("regex")). Since you're not using JavaScript, I suppose you'd also need to replace "createEvent" in document with document.createEvent.
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: IE and OnChange

16 Jun 2015, 20:38

very simple to you perhaps... lol I will work on this over the coming weeks. It is going to take a lot for me to figure it out as I'm not one to write new code, I mostly borrow the gems y'all create. Thank you for the point in the right direction.
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: IE and OnChange

24 Nov 2015, 05:52

try

Code: Select all

wb.Document.All.category.onchange()
or

Code: Select all

wb.document.getElementById("CATEGORYID").value := 2402
wb.document.getElementById("CATEGORYID").onchange()
I am new to ahk may be two months, and I am also stuck I got passed from this situation but I also need find the way to make ahk wait for element to get loaded no web page here is the link of my issue :headwall:

https://autohotkey.com/boards/viewtopic ... nge#p59089
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: IE and OnChange

08 Nov 2017, 14:15

I finally got a decent understanding of creating and dispatching Events on a page! Check out my tutorial here. Half way down the page I also demonstrate my syntax writer to help write the code.
:bravo:
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, mikeyww and 131 guests