Simple Javascript Form Check

This is something I whipped up to make sure people weren’t submitting forms missing vital information, but I didn’t care if the information was wrong. It’s for a back end thing, the general public should be thoroughly checked (it’s a lowest common denominator thing) but if this is an important work related thing your not very likely to mess it up to terribly (but, check for anything that will break your script just in case they do). In this case it was a form that stores client information, if the names in the wrong place it can be edited and it’s not a big deal, but if you really want to ensure accuracy you can run additional checks inside each of the ifs for that articular thing.

Snipplr: http://snipplr.com/view/46271/simple-javascript-form-check/

Two things I’d like to note about this. First, if you have a very large form it should probably be done with a script that looks at all elements instead of using a line per element. Second, you have to make the submit button type="button" instead of type="submit" or you have to make it return true/false upon completion. I don’t see much of an advantage either way so I used a button for simpler testing and never changed it back.

Leave a Reply

Your email address will not be published. Required fields are marked *