Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Correcting Annoying Validation, versioning until corrected
<!doctype html>
<html lang="en">
<meta charset="utf-8">
label {
display: inline-block;
width: 96px;
<div><label>First Name</label><input id="fname" /></div>
<div id="err4-fname" style="color: red"></div>
<div><label>Last Name</label><input id="lname" /></div>
<div id="err4-lname" style="color: red"></div>
<div><label>City</label><input id="city" /></div>
let fnameEl = document.getElementById('fname');
let lnameEl = document.getElementById('lname');
let lastError;
function confirmEntry() {
let errEl = document.getElementById('err4-' +;
if (this.value) {
errEl.innerHTML = '';
lastError = '';
else if (lastError) {
else {
lastError = this;
errEl.innerHTML = 'The above field is required';
fnameEl.addEventListener('blur', function() {;
lnameEl.addEventListener('blur', function() {;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment