Simple form verification _javascript techniques implemented by JavaScript

Source: Internet
Author: User

Form validation is almost indispensable, some form validation is done in the background, and some are using JavaScript in the front-end to complete the basic verification, so that you can effectively reduce the pressure on the server, the following describes the most simple JS implementation of form verification. The code example is as follows:

 <! DOCTYPE html>  
 

The code above implements the most basic form validation, which is not to allow the contents of the form to be empty, and here is a brief introduction to its implementation:

In JavaScript code, create the Chkform () function to validate the form, and here's a brief introduction to the secondary function:

document.getElementById ("username"). Value

The above code can get the value of an object with an ID of username, and then determine whether the value is empty by using the IF statement, and return FALSE if it is null, which is important, otherwise the form will be submitted even if the form content is empty and the validation effect will not be achieved. This is also true for the second if Judgment statement, which is not covered here.

Two. onclick= "return Chkform ()", the function of this statement is to click the Submit button will be executed when the Chkform () function used to validate the form, here special emphasis do not forget to add a.

The above mentioned is the entire content of this article, I hope you can enjoy.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.