1

I am currently looking for an event listener for input type=checkbox that fires when disable state changes

  1. any trigger changes disable state of any checkbox on the site
  2. event listener for state change fires

I do not want to add the event to the first trigger which changes the checkbox state. It must be independent, for the trigger may change.

What I have tried so far:

$(function(){
      $('.trigger').live('click', function(){            
          $('.eventbox').attr('disabled','disabled');
      });


      $('.eventbox').live('change', function(){
          alert('state changed');
      });
 });

Unfortunately change doesn't work.

thank you for your help. jesse

Jesse
  • 11
  • 1
  • 3
  • Do you mean "disable" or "checked" state? – Ivan Ivanic Mar 08 '11 at 12:36
  • how do you disable the checkbox? do you use the `.button('disable')`? – Val Mar 08 '11 at 12:37
  • change only tracks if checkbox is checked or not checked, i.e. alteration of those two. Are you sure you want to track if checkbox is enabled/disabled? Sorry for repeated question, but I want to be sure :) – Ivan Ivanic Mar 08 '11 at 12:43
  • Look here: http://stackoverflow.com/questions/240592/is-it-possible-to-listen-for-changes-to-an-objects-attributes-in-javascript – Ivan Ivanic Mar 08 '11 at 13:23
  • looks quite promising, but didn't work with: $('body').change(function(event){ event = event || window.event; console.log(event.target); console.log(event.srcElement); }); it always shows the click event, but not the attribute changes – Jesse Mar 08 '11 at 14:06
  • this indeed looks good: https://www.adaptavist.com/display/jQuery/Mutation+Events – Jesse Mar 08 '11 at 14:17

2 Answers2

0

can you put a trigger on the thing that does the checkbox disabling? By that I mean, if you have some button that as a side effect disables some checkboxes on click, could you tack you listener onto the click of the button?

Nathan Feger
  • 19,122
  • 11
  • 62
  • 71
  • Sorry, I don't get your answer. I do not want to add something to the trigger, for it may change or other triggers may cause disabling of a checkbox. These other triggers may not be click events. – Jesse Mar 08 '11 at 12:43
0

Try this. I think you really want to track checking/unchecking of checkbox and not enabling/disabling.

$(function(){
      $('.trigger').live('click', function(){            
          $('.eventbox').removeAttr('checked');
      });


      $('.eventbox').live('change', function(){
          alert('state changed');// this will be fired only if state was checked
      });
 });
Ivan Ivanic
  • 2,982
  • 1
  • 20
  • 21
  • sorry ivan, but i do not want checking/unchecking. i want disabling of checkboxes. as i wrote. – Jesse Mar 08 '11 at 12:54
  • Ok. I asked you in original post :) You did not answer so I took liberty to interpret :D – Ivan Ivanic Mar 08 '11 at 12:58
  • no problem :) by the way: even on check/uncheck the change event does not work – Jesse Mar 08 '11 at 13:02
  • I investigated this a bit and there are some solutions but I do not like them :) Check this links: http://www.west-wind.com/weblog/posts/478985.aspx http://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMAttrModified http://help.dottoro.com/ljdchxcl.php http://stackoverflow.com/questions/2844018/event-to-listen-to-attribute-changes – Ivan Ivanic Mar 08 '11 at 14:13