eozzy
eozzy

Reputation: 68750

Form reset causes issues (jQuery)

$(function () {
    function f1() {
        if (this.checked) {
            $('select[name=two]').removeAttr('disabled');
        } else {
            $('select[name=two]').attr('disabled', true);
        }
    }
    $('input[name=one]').change(f1).triggerHandler('change');
    $('.reset').click(function () {
        $('input[name=one]').removeAttr('checked').end().click(f1);
    })
});

... almost works. Please check fiddle here.

But the problem is:

  1. Check 'one' and select 'two' from dropdown.
  2. Click 'reset'.
  3. Check 'one' again and try selecting 'two' from dropdown.

Dropdown gets disabled automatically!

Many thanks for your help!

Upvotes: 2

Views: 174

Answers (1)

BalusC
BalusC

Reputation: 1109635

You should rather trigger the change handler during reset. Replace

$('input[name=one]').removeAttr('checked').end().click(f1);

by

$('input[name=one]').removeAttr('checked').triggerHandler('change');

Here's a new fork.

Upvotes: 2

Related Questions