I have an object with an event attached to it. Is there a way to trigger this event through JavaScript?
Here is an extremely simplified version of the scenario:
When the user changes the select box above, the event fires. When JavaScript changes the selectedIndex, the event does not fire. Can I add something to the JavaScript to trigger the event? I cannot change the function inside the attachEvent line, and I cannot make the object static (like <select onchange="...code..."> )... the attachEvent code/function is part of a huge js file written by someone else.
Here is an extremely simplified version of the scenario:
Code:
obj = document.createElement("select");
obj.appendChild(document.createElement("option"));
obj.appendChild(document.createElement("option"));
obj.attachEvent("onchange", function () { alert("test"); } );
document.body.appendChild(obj);
//this line should trigger the alert in the onchange event
obj.selectedIndex = 1;
When the user changes the select box above, the event fires. When JavaScript changes the selectedIndex, the event does not fire. Can I add something to the JavaScript to trigger the event? I cannot change the function inside the attachEvent line, and I cannot make the object static (like <select onchange="...code..."> )... the attachEvent code/function is part of a huge js file written by someone else.