Skip to content

Instantly share code, notes, and snippets.

@erikras
Created March 18, 2018 11:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikras/8e49884f040426223eb3306112c4c5b9 to your computer and use it in GitHub Desktop.
Save erikras/8e49884f040426223eb3306112c4c5b9 to your computer and use it in GitHub Desktop.
A function to call focus() on the first form input that has an error
function focusOnFirstError(formName, hasError) {
const form = document.forms[formName]
for (let i = 0; i < form.length; i++) {
if (hasError(form[i].name)) {
form[i].focus()
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment