Checkbox reset when onClick handler is invoked with dispatchEvent

Running the following jsfiddle:

I set a input checkbox to "true" when clicking on a link, and then programatically trigger the onClick handler for the checkbox field.
In Chrome, all is well but in IE11 the checkbox is reset to false when the onClick handler is executed.

Any ideas on why IE does this?
Stefan LennerbrantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Stefan LennerbrantAuthor Commented:
I just tested with changing the checkbox to be "checked" to begin with, anticipating that it would retain that checked state in the onclick handlier in IE
However, the checkbox is still "false" even then, using IE. Strange?
Julian HansenCommented:
The problem is that you have this
<a href="javascript:document.F.ClickField.checked = true; /*ClickTest();*/FireEvent(document.F.ClickField, 'click');">Click</a>

Open in new window

The first bit is setting the checkbox ticked and then in the FireEvent you are sending the onclick which is unticking the box.

It looks like a timing issue between the two browsers that is resulting in a different result.

Could I ask what it is you are trying to do - it seems rather involved and possibly could be done a lot easier.
Stefan LennerbrantAuthor Commented:
Aha, you mean that the onclick handler actually performs the action of ticking/unticking the checkbox as well?
Well ok, of course!

It's a little strange, then, that the checkbox ends up "false" regardless of initial state.
One would guess that onclick would toggle the state, not reset it?
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Julian HansenCommented:
No it makes perfect sense.

You have
javascript:document.F.ClickField.checked = true

Open in new window

Which says set checkbox true. If false to begin with it is checked, if true to begin with - still checked.

No you fire a click against a true (checked) checkbox - irrespective of initial state - checks the box off - at least in IE anyway - which intuitively is what you would expect.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stefan LennerbrantAuthor Commented:
So, one could say that Chrome (and Firefox and Safari) is at error here - and IE does the right thing?
Julian HansenCommented:
I am reluctant to give IE credit for anything - they usually get the interpretation wrong and I would need to do more research into this to find out why the behaviour is as it is  - there might be a good reason for it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.