I have a form containing various fields.
See jsFiddle demo.
My aim is to enable the submit button only when the user has filled in all fields.
So far,
Try utilizing .siblings()
, .map()
to compile values of form
elements , Array.prototype.every()
to return Boolean
representation of input
, textarea
values , set disabled
property of form input[type=submit]
element
$("form *[required]").on("input change", function(e) {
$(this).siblings("[type=submit]").prop("disabled"
, !$(this).siblings(":not([type=submit])").add(this).map(function(_, el) {
return el.type === "radio" ? el.checked : el.value
}).get().every(Boolean)
);
});