Advanced Java and Web Technologies for JNTUK
Blog providing beginner tutorials on different web technologies like HTML, CSS, Javascript, PHP, MYSQL, XML, Java Beans, Servlets, JSP and AJAX

11/02/2015 Categories: Javascript. No Comments on Form Validation

One of the best uses of client-side JavaScript is the form validation. The input given by the user can be validated either on the client-side or on the server-side.


By performing validation on the client-side using JavaScript, the advantages are less load on the server, saving network bandwidth and quicker response for the users.


Form input can be validated using different events, but the most common event used is submit i.e when the submit button is clicked. Corresponding attribute to be used is onsubmit of the form tag. Let’s consider a simple form as shown below:



The above example can be written in another way as shown below:



The general validation process is to check whether the user input matches the requirements. If it matches return true which will make the browser shift the control to the page mentioned in the action attribute of the form tag. Otherwise display appropriate error message and return false which will make the control stay in the current page.

Related Links:

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

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

Scroll Up