Using Inline Form Validation

Introduction

Javascript alert boxes have long been used for validating HTML forms. For example, if you forget to type your name into a contact form, then a Javascript alert pops up telling you about your error and how to correct it. While this is a lot better than no warning message or validation at all, I find alert messages quite annoying, ugly and outdated.

What I’d like to do in this article, is show you a more elegant way of displaying error messages cleanly, using some easy to implement Javascript. This not only makes your forms a lot cleaner and more usable, but also shows your attention to detail as a web designer.

The Finished Product

Here

This entry was posted in Programming. Bookmark the permalink.

40 Responses to “Using Inline Form Validation”

  1. Anonymous says:

    Hi Eddie, Thanks for the excellent explanation of inline form validation. Your article taught me just what i needed.

  2. Anonymous says:

    You guys are so smart! I am jealous!

  3. Megan Richardson says:

    Have been searching for the 'simple' answer all night – thanks for making it easy to understand.

  4. Sam says:

    That is so cool.
    And all this time Ive been using alert boxes.
    Never again

  5. Dan says:

    Very nice, thank you very much for explaining this clearly!

  6. Charm says:

    Brilliant! Thank you for the wonderful tutorial.

  7. srinu says:

    Very useful thank u very much

  8. Byron says:

    Very Nice, but what if Java is disabled? This is what I am looking for, but I want it all to be server-side based.

    [Editors note] Hi Byron, it's very rare these days that JavaScript is disabled. I'd say it's enabled on 99% of PC's. If it is disabled you'd have to use a server-side validation technique.

  9. JJ says:

    Straight to the point. Thanks for the example!

  10. Jo Adamson says:

    Fantastic explanation that was ideal to solve my problem. Liked the step-by-step approach.
    Great!

  11. Philippe says:

    I have been looking for something smart for a while and didn't find anything….. your script is great as so simple… it makes me flush to see how simple things can be….. when you are skilled.

    Thanks again,
    Philippe

  12. Francesco says:

    Nice, very Nice…simple, cleare and informative.

    Well done

  13. Sue Gerrey says:

    Thanks so much for the script. I have looked everywhere for something like it and appreciate your sharing it.

  14. Lena says:

    Thank You for letting me leave the use of alert boxes behind.

  15. Ajith Joseph says:

    This was what I wanted

  16. Radhab Shrestha says:

    Very effective for the website verification. Thanks for the content it is useful for all.

  17. hari says:

    good stuff

  18. Pal says:

    very simple n useful. pls teach some more useful scripting..

  19. Julean says:

    I've have not seen a more elegant yet simple piece of script. So easy to modify.

    Very nice work! A big thanks!!!

  20. rakeshnagpure says:

    Excellent work you have done.
    I inspired and adoptted your coding.
    thanks a lot my friend.

  21. shridhar says:

    Its what i was looking for and need of the hour thanx a lot

  22. yahoozled says:

    i can't tell you how great it was to come across this. i've been using complicated php-scripts on receiving end to validate and now i can move those rules back here and pre-validate.

    thanks for being so bloody clear and such a simple example!

    btw, if you add {font-family:Tahoma;font-size:8px;} you can eliminate alot of the repeated CSS.

  23. gopi says:

    simply Fantastic!

  24. mathi says:

    hi! your explanation realy good…keep on..

  25. Erik says:

    Dead On! This was short, concise, and to the point.
    Excellent explaination and example.
    I would love to see a similar walkthrough for radio buttons, but with a little sleep and this example, I'm sure I can figure it out.

    Well Done!!

  26. Debra W. says:

    GREAT – thank you – and it teaches me about hidding and showing elements too

  27. sam says:

    Very good Example

  28. mad(real initials) says:

    God bless you. I have been trying to figure this out for a class. The prof keeps giving hints. We are allowed to find answers online. :-) I just didn't know the term "inline".

  29. anthony says:

    awesome, any easy way to validate the email for correct formatting; ie. a real email address?

  30. Peter says:

    Interesting, but what I am looking for is something that will validate fields as the user exits each one. onblur() I suppose… Any ideas on that?

  31. Garrett says:

    Digg it!

  32. Cheese says:

    Brilliant cheers!

  33. shrilakshmi says:

    It's really fantastic.It is explained in so simple way.This is what i wanted.Thank You

  34. Daniel says:

    Thank you for such clear explanation and for sharing this code. I am wondering how you would use this code with two forms on the same page.

  35. jorgerosa says:

    THANK YOU! Just what i needed.
    And guess what: Simple clean code and works just like a dream! :D

  36. Simon says:

    Wow the simple answer I was looking for!!!!! :)

  37. Simon says:

    wow amazing ! what I was looking for!

  38. Dudu says:

    Muito bom!!! Very good!

  39. Alex Jordan says:

    Great script, I’ve been looking for this for a while. The only problem I’ve found is that I can’t seem to get it to work in Firefox, it works perfectly in IE7 so I don’t know what is wrong there. If you have any suggestions then I would appreciate it. Javascript is definately enabled in FF before you ask.

    Many thanks,
    Alex

  40. parixit says:

    Thanks !
    This is exactly what I was looking for.

Leave a Reply