JavaScript Input Field Validation-Collection of common programming errors

If you open your browser’s console (F12 in Chrome and IE; ctrl-shift-K in FF) you’ll see that your code gives this error:

Uncaught ReferenceError: validationMessage is not defined 

…because you declared the variable as validMess. Then in your update to the question you renamed it to validMessage. But still your other code is referring to validationMessage.

// WRONG:
var validMessage = "Please correct the following errors: \r\n";

// RIGHT:
var validationMessage = "Please correct the following errors: \r\n";

Demo: http://jsfiddle.net/JH8hg/

UPDATE to go with your latest update:

In your jsbin.com demo, you have attempted to add an onsubmit handler to a button:


…but buttons don’t have an onsubmit event so this should be added to the form element:

  

And that form element doesn’t have a closing tag.

And you forgot to give an id="email" to your email field which means you got a JS error when you tried to use document.getElementById('email').value.length.

Working demo with those things fixed: http://jsbin.com/ukepuh/1/edit

Originally posted 2013-11-13 09:50:07.