Skip to content

Instantly share code, notes, and snippets.

@wattry
Last active October 5, 2018 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wattry/1318ea40d7e9ecca9f9ff8e4a4a8de6d to your computer and use it in GitHub Desktop.
Save wattry/1318ea40d7e9ecca9f9ff8e4a4a8de6d to your computer and use it in GitHub Desktop.
JS function to enable and disable inputs as the previous was filled
function validateRelationshipForm(inputs) {
for (i = 0; i < (inputs.length - 2); i+=2) {
if (inputs[i].value.length > 0) {
inputs[i + 1].disabled = false;
if (inputs[i + 1].type == "button") {
inputs[i + 1].classList = ("btn btn-success");
}
} else {
inputs[i + 1].disabled = true;
if (inputs[i + 1].type == "button") {
inputs[i + 1].classList = ("btn btn-secondary");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment