I have a html-page loaded in a CDialog in an MFC application, using the IE8 engine, and an instance of CDHtmlDialog. The html-page contains <input> elements, and includes jQuery. In said jQuery, I have this code:
$(function()
{$
$('#Left').change(function()
{
$('[id$=left]').prop('disabled', ! $(this).is(':checked') );
}).change();
});
Which essentially just keeps some inputs and selects (chosen by id convention) disabled or enabled, based on the checkbox with the id #Left.
The issue being: When I change the checkbox from the C++ code like so:
// Get pElements checkbox through doc->getElementsByTagName("input")
CComQIPtr<IHTMLInputElement> spInputElement(pElement);
spInputElement->put_checked(true);
then the change event does not fire (possibly to avoid infinite recursion), and the other inputs never update. Is there a way in which I can fire the change-event explicitly from my C++? I would prefer not to require all checkboxes to have specific html-code (such as an explicit onchange=”…”), as that would be impractical for maintenance.
So, thanks to amadeus, I got it figured out. This is the code that works, so everyone else can just copy-paste it if they need it.
Note that this will not fire any events described in JQuery, but it will get all those that are declared directly in the html as
onchange="..."