JavaScript error messages displaying correctly