Home     |      Learn AJAX     |      Forum     |      Register     |      Submit Resource     |      Submit Article      |      Contact Us

Home JavaScript
 

Properly Implementing JavaScript Form Validation

 

Form validation is common in most websites today as every developer or website owner wants to know more their users. Form validation is also used for interaction purposes to ensure that the right type of data is added. JavaScript form validation is a special type of validation since it can provide the interactivity and validation with the user without forcing any page reloading.


However, there are certain things that a developer should remember to ensure that the form validation is both interactive as well easy to use for developers.


To know how to properly implement JavaScript form validation, let’s take a look first on how NOT to implement JavaScript form validation. Unfortunately, some of these practices are observed in some websites.


• Validation comes from JavaScript only – yes, this is JavaScript form validation but that doesn’t mean validation should only come from JavaScript. If this practice is being followed in a website, there is a big chance that the website could be hacked since JavaScript could be reconfigured according to the hacker’s preferences. On the other hand, tying JavaScript validation with server-side validation will ensure the website’s security.


• JavaScript as the sole rendering application – there are developers that have been thinking that since JavaScript and Ajax are very popular nowadays, everyone is trying to adopt them. A knowledgeable user will never give into the fact that a website is in JavaScript form only. There are a lot of reasons why a user will not use JavaScript in his or her browser. It’s not only the bandwidth problem but also in browser compatibility.


• Telling them they can’t use the site because their browsers can’t read JavaScript – this is just plain wrong since the goal of a website is to have as many visitors as it can. Everyone is using a different browser and shooing them away since they have a particular interest in a specific website will drive away potential customers. Developers should always have a lighter non-JavaScript version so that every user would enjoy the website.


Form validation in non-JavaScript methods could still be implemented through server side validation.


There are two ways in implementing form navigation in terms of execution:


1. Validating them altogether when the “submit” or any related button is pressed - This arrangement is very ideal for smaller forms to fill out in a specific website.


2. Validating as the move to the next box – if you have a large form to be filled out, evaluate each data entered and alert the user if they entered the wrong format as they go through. If the user still has to press “submit” before knowing one of the data fields has the wrong type of data, this will discourage the users from going further. This validation measure is the combination of JavaScript as the client side submits the information to the server and receives the same response from the server. This data will eventually be loaded in the client side to inform the user of the validity of the data provided.



Read Next: Implementing Microformats Effectively



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links