Form onsubmit event-the best way to implement the verification before the form is submitted, formonsubmit
Implementation Method of verification before page submission:
Form should also have an onsubmit event before submission. The function of this event is to automatically execute the specified item before the form is submitted.
Note that the return value in onsubmit = "return check ()" must be added. Otherwise, the return value of check is submitted even if it is false. That is to say, onsubmit = "return false" indicates that the submission is not executed; onsubmit = "return true" or onsubmit = "return" indicates that the submission is executed.
The HTML is as follows:
<Form action = "admin-add-user-proc.php" onsubmit = "return check ()"> <div class = "category-title"> <div style = "cursor: pointer; "id =" "class =" category-item "> <p> <span> Logon Information </span> </p> </div>...
JS:
Check = function () {if ($ ("# input_username"). val (). length = 0) {alert ("username is blank! "); Return false;} if ($ (" # input_realname "). val (). length = 0) {alert (" the real name is blank! "); Return false;} return true ;}