views:

27

answers:

2

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

thanks

+2  A: 

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.

Gert G
Couldn't say it better myself.
some
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
@BillThor - That was covered in my second sentence.
Gert G
@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
@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. ;)
Gert G
@GeryG - Unfortunately, I frequently run across form where JavaScipt validation is used to enable fields. No JavaScript = only some of the required fields = sever side failure due to missing fields. This is what should be avoided.
BillThor
@BillThor - Don't judge the technology on the skill of the programmer.
Gert G
@GeryG - Not blaming the technology, just the all to typical use of it. It may not always be the skills of the programmer, as they may be implementing something they don't agree with.
BillThor
@GeryG, so based on what you said, if all users disable java script on their browser then there would be no need for the script at all? when would it be justifiable to use JS? are you saying that it's always better to use server side scripts?
Noona
@Noona - You should always have server side validation. Client side validation is a progressive enhancement that makes the form more user-friendly.
Gert G
+2  A: 

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.

Rup

related questions