Reputation: 6238
I have a form with some selection input field, if the selector is equal to something it disable some other input fields. This working good.
But when the form refresh (with the pre-loaded input), for example in the case the form is not valid, the others fields are not disabled.
My code:
$('#some_selector_id').change(function() {
var val = $(this).val();
if (val == "something")
{
$('#other_field').prop('disabled', true);
} else {
$('#other_field').prop('disabled', false);
}
});
To maintain the code dry, I don't want to repeat code, there is a method to follow like: if .change
or .val_is
do this
?
Upvotes: 0
Views: 92
Reputation: 11317
From the dom ready event, after you have bound the change event, you should just trigger the event manually:
$('#some_selector_id').change();
That will cause the change handler to run.
Upvotes: 1