Simple Form Verification implemented by javascript, and form implementation by javascript

Source: Internet
Author: User

Simple Form Verification implemented by javascript, and form implementation by javascript

Form Verification is almost indispensable. Some Form Verification is completed in the background, while others use JavaScript to complete basic verification at the front end, which can effectively reduce the pressure on the server, the following describes the simplest form verification implemented by JS. The code example is as follows:

<! DOCTYPE html> 

The above code implements the most basic form verification, that is, the form content is not allowed to be blank. The following describes the implementation process:

1. In JavaScript code, create the chkform () function to verify the form. The following describes the next function:


The code above can obtain the value of the object whose id is username, and then use the if statement to determine whether the value is null. if it is null, return false. This statement is very important, otherwise, even if the form content is empty, the form will be submitted, and the verification effect will not be reached. The second if judgment statement is also used, so we will not introduce it here.

II. onclick = "return chkform ()". The function of this statement is to execute the chkform () function to verify the form when you click the submit button. Do not forget to add return here.

The above is all the content of this article. I hope you will like it.

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: 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.