Form onsubmit event-the best way to implement the verification before the form is submitted, formonsubmit

Source: Internet
Author: User

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 ;}


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.