JavaScript Validation for XHTML:
Get a reference to the form with JavaScript. Validate each input field for a value. Compare passwords, but only if passwords have been given. (Stops comparison of empty passwords being considered the same). Check radio buttons have been selected. Display any error messages (that have been put inside an array during validation) as an unordered list beneath the form.
A Pen by Matt Trainer on CodePen.