Created
March 18, 2018 11:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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