3

I have this bound event on all matching inputs:

$('input[name$="_keyword"]').each(function() {
    $(this).bind("propertychange keyup input paste", function(event){
    if ($(this).val() != '') {
        $(this).prevAll('select').attr('disabled', true);
    } else {
        $(this).prevAll('select').attr('disabled', false);
    }
    });
});

This will disable the related dropdown menu if text has been typed into it's text input.

However, if I type someone in one of the _keyword inputs, thus disabling the related dropdown menu, and hit my HTML reset button, all fields in the form will clear but the dropdown menus will not enable. How can I have these enable when the reset button is clicked?

<input type="reset" value="Reset"/>

JSFIDDLE

6 Answers 6

3

You can register a handler on the form's reset event to re-enable the drops-downs:

 $('form').on('reset', function() { $('form select').removeAttr('disabled'); });
Sign up to request clarification or add additional context in comments.

Comments

2

You'll need to trigger one of the events in the bind (eg propertychange) via a click handler on the reset button.

$('input:reset').click(function() {
  $('input[name$="_keyword"]').val('').trigger("propertychange");
});

See working fiddle:

http://jsfiddle.net/GHpmh/1/

Comments

1

A form reset does not trigger any of those events you are listening for. You also need to bind the "reset" event. Unfortunately, you have to bind that at the form level, not on individual fields, as not all browsers will bubble the reset event to fields.

Comments

1

How about adding a click handler to your reset button to do it? For example:

$("input[type=\"reset\"]").on("click", function(event) {
    $("select").attr('disabled', true);
})

Comments

1

You can listen for the reset event on the form and enable the selects there

$('form').on('reset', function() {
    $('select', this).prop({disabled: false});
});

DEMO

Comments

0

combining a couple of the answers above, I would do this to reset the select elements in a form and trigger the change function

$('form').on('reset', function() { $('form select').val('all').trigger('change'); });

use an HTML reset button inside of your form markup

<input type="reset" id="reset" value="Reset">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.