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:
document.getElementById("username").value
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.