, Javascript- VBA fireevent.
Mozilla Dev - EventTarget.fireEvent
.
Option Explicit
Sub Test()
'* Tools->References->Microsoft HTML Object Library
'* Tools->References->Microsoft Internet Controls
Dim ie As SHDocVw.InternetExplorerMedium
Set ie = New SHDocVw.InternetExplorerMedium
ie.Visible = True
ie.navigate "n:\TestWebOnChangeManually.html"
Dim obj As Object
Stop '* i use this pause to dismiss Allow Block Content footer warning message
Dim dom As MSHTML.HTMLDocument
Set dom = ie.document
Dim textSource As MSHTML.HTMLInputElement
Set textSource = dom.getElementById("source")
textSource.innerText = "poked"
'https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/fireEvent
'* not sure what to place in second parameter
textSource.FireEvent "onchange", Nothing
End Sub
html
<html>
<head/>
<body>
<input id="source" type="text" onChange="MyChange('source')"></input>
<input id="someOtherControlToFocusSwitchTo" type="text" value="foo"></input>
<script>
function MyChange(eleId)
{
if (eleId)
{
var ele = document.getElementById(eleId);
if (ele) {
alert(ele.value);
}
} else
{
alert("MyChange fired with no param");
}
}
</script>
</body>
</html>
, -, , dispatchEvent , SO FireEvent IE11, . VBA javascript, SO onchange ?, SO JavaScript?
' Fire the onChange event...
Dim objEvent
Set objEvent = doc.createEvent("HTMLEvents")
objEvent.initEvent "change", False, True
e.dispatchEvent objEvent
, , .