0

I've implemented this with the code below:

$(':input[type!="submit"]', form.get(0)).live ('change', function (e) {
    form.find (':submit').removeAttr ('disabled');
});

This works perfectly, however, when the user changes the element back to its original state, the submit button is still enabled:

Example:

  • originally form has a checkbox checked - submit button will be disabled
  • user unchecks the checkbox - submit button will be enabled
  • user checks the checkbox again (back to original state) - submit button is still enabled (I'd like it to be disabled again)
birdy
  • 9,286
  • 24
  • 107
  • 171
  • Perhaps you'd like to say `if($(this).val != '')` as in [this question](http://stackoverflow.com/questions/1594952/jquery-disable-enable-submit-button)? – kush Mar 27 '13 at 15:04
  • `live()` is deprecated. Use `on()` instead. – techfoobar Mar 27 '13 at 15:04

1 Answers1

1

Try this:

$(document).on('change', 'input[name=cb1]', function () {
    $('input[type=submit]').prop('disabled', $(this).is(':checked'));
});

jsFiddle example

I'm using .on()'s event delegation based on your your use of .live().

j08691
  • 204,283
  • 31
  • 260
  • 272
  • Six more checkboxes with six related submit buttons? – j08691 Mar 27 '13 at 17:26
  • no only one submit button. Please check this update on jsfiddle http://jsfiddle.net/3VB3C/1/ out of three checkboxes two are checked to begin one and one is not. the behavior isn't what is expected. – birdy Mar 27 '13 at 18:18
  • I'm not following how you want that new fiddle to function. What's the criteria to enable/disable the button based on the three checkboxes? – j08691 Mar 27 '13 at 18:21
  • So out of three checkboxes. first is unchecked and other two are checked. When the unchecked checkbox is checked by the user, then the submit button is not being enabled (problem). When this same checkbox is unchecked (original state) then the submit button is enabled (problem, because now it should be disabled since that was the original state). The criteria is that only enable the submit button when state of the checkboxes in a form changes from their original state – birdy Mar 27 '13 at 18:25