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