Validate forms with onsubmit () and block illegal commits (using jquery)

Source: Internet
Author: User

Code detection textarea fill in the length, not filled out when prompted to re-fill, less than 15 characters when prompted to be longer than 15 characters, successful display of the completed recommendations.


1 <Scripttype= "Text/javascript">2 //jquery Code3 functionconfirm ()4 {5    if($("#advice"). val (). Length== 0)6 {7    Alert ("We can ' t see your advice. Maybe you should fill the form first.");8    $("#advice"). focus ();9    return false;Ten } One Else if($("#advice"). val (). Length<= the) A { -    Alert ("Your advice should longer than."); -    $("#advice"). focus (); the    return false; - } - Else - { +    Alert ("Thank for your advice! you'll get out reply on hours for advice:\n"+$("#advice"). Val ()); -    return true; + } A at } - </Script> - - <formAction=""Method= "POST"OnSubmit= "return confirm ();" > -    <textareaID= "Advice"rows= " the"cols= " the"placeholder= "Give us some advice?"></textarea> - <inputtype= "Submit"value= "Thank You"/> in </form>
> Key points

1. It is necessary to have onsubmit= "return confirm (); the word" return "is indispensable.
2. Self-complete Web page structure.

Validate forms with onsubmit () and block illegal commits (using jquery)

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.