0

I have a checkbox:

<input id="abcd" name="abcd" type="checkbox" onclick="doSomething(this, 'otherparams');">

Now, I have some other code, that could do the following:

document.getElementByID("abcd").checked=true;

I want doSomething to fire even when I change the state of the checkbox programmatically. (Am ready to use anyone of onchange/onclick in the checkbox input)

Here is what I am trying: http://jsfiddle.net/hfovh2xm/6/

To give some context: Its a large piece of code with multiple interacting modules (a module that I do not want to edit could set the checkbox value, I would like to detect that change in my module).

workwise
  • 1,003
  • 16
  • 33
  • You have to trigger the event yourself. Here you can simply call the `doSomething ` function instead. Note that you have `onclick` attribute not `onchange`! – Ram Oct 25 '14 at 12:53
  • how about `$("#abcd").trigger("click")` ? or simply call `doSomething($("#abcd")[0], 'otherparams');` – Banana Oct 25 '14 at 12:54
  • @Vohuman I tried even with onchange. Still does not work as in the fiddle. Of course last resort is to fire it myself, but its a large piece of code with multiple interacting modules (a module that I do not want to edit could set the checkbox value, I would like to detect that in my module). – workwise Oct 25 '14 at 13:01

0 Answers0