How to get error messages to display on the form, rather than after the page is refreshed?
You can use contributed module Clientside Validation which is very close to your requirement.


  This module adds clientside validation (aka "Ajax form validation")
  for all forms and webforms using jquery.validate. The included
  jquery.validate.js file is patched because we needed to be able to
  hide empty messages.