Skip to content

Instantly share code, notes, and snippets.

@Steamforge
Last active January 14, 2020 06:44
Show Gist options
  • Save Steamforge/e9a4a62369a4ebf992674e2f874bd906 to your computer and use it in GitHub Desktop.
Save Steamforge/e9a4a62369a4ebf992674e2f874bd906 to your computer and use it in GitHub Desktop.
Form Validation
<form id="signUpForm">
<input type="email" id="emailField" required>
<button id="okButton" disabled>OK</button>
</form>
<script>
const signUpForm = document.getElementById('signUpForm');
const emailField = document.getElementById('emailField');
const okButton = document.getElementById('okButton');
emailField.addEventListener('keyup', function (event) {
isValidEmail = emailField.checkValidity();
if ( isValidEmail ) {
okButton.disabled = false;
} else {
okButton.disabled = true;
}
});
okButton.addEventListener('click', function (event) {
signUpForm.submit();
});
</script>
@AloisJanicek
Copy link

On line 12, you are assigning value to an undeclared variable. Aren't you missing const or var keyword at the beginning of the line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment