0

what are the advantages of validation on the client side using a client side script such as Javascript?

thanks

2
  • possible duplicate of form validation with javascript vs php Oct 3, 2010 at 22:43
  • Remember to always check the parameters on the server side: You might expect a username of 6-20 characters and feed it into a sql-query but what you actually get is 10 megabytes of random data and your sql server might not handle that in a graceful way.
    – some
    Oct 3, 2010 at 22:48

2 Answers 2

2

A better user experience. They get validation results quicker, without a server round-trip. It also allows you to do validation of fields that are difficult / you don't want to send back through a page cycle, such as passwords and credit card numbers.

It's fairly easy to set up nowadays - there's plenty of JavaScript frameworks you can just drop in, the set styles on your input fields to describe validation and wire up a submit handler to trigger validation. e.g. jQuery validate.

However you must always cope for the no-JavaScript case, and you must always server-side validate too.

2

The advantage is that the user doesn't need to reload the page just to find out that there's an error in the input. This said, you still have to do server-side validation, since users can turn off or manipulate the JavaScript in order to submit nonsense data to the server.

10
  • 1
    Couldn't say it better myself.
    – some
    Oct 3, 2010 at 22:44
  • Depending on the browser JavaCcript may not be available to the user, so it is a good idea to allow the form to work without JavaScript. Users may also disable JavaScript from untrusted sites for security reasons.
    – BillThor
    Oct 3, 2010 at 23:34
  • @BillThor - That was covered in my second sentence. Oct 4, 2010 at 1:12
  • @GertG - No offense was intended. Some people turn off JavaScript to enable hacking. However screen readers, and text mode browsers often don't have JavaScipt. And other users disable JavaScript for security purposes. Sites with forms that can only be filled with JavaScript enabled have a high risk that some customers will abandon the form.
    – BillThor
    Oct 4, 2010 at 12:53
  • @BillThor - No offense taken. I surf the web with JS mainly turned off. As for screen readers, they read what the browser offers them. With WAI-ARIA, they're happier than ever. And having validation both on the client and server offers everyone validation. ;) Oct 4, 2010 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.