jquery implements form validation and prevents illegal submission of _jquery

Source: Internet
Author: User

Code detection textarea fill in the length, not filled out prompts need to be filled out, less than 15 characters when the hint needs longer than 15 characters, when successful display the suggestions filled out.

<script type= "Text/javascript" >
//jquery code
function confirm ()
{
if ($ ("#advice"). Val (). Length = = 0)
{
alert ("We can ' t your advice.")  Maybe You should fill the "form");
$ ("#advice"). focus ();
return false;
}
else if ($ ("#advice"). Val (). length <=
{
alert ("Your advice should longer than.");
$ ("#advice"). focus ();
return false;
}
else
{
alert ("Thank for your advice!  You'll get out reply the hours for advice:\n "+$ (" #advice "). Val ());
return true;
}
</script>
<form action= "method=" POST "onsubmit=" return confirm (); ">
<textarea id=" advice "Rows=" "cols=" placeholder= "give us some advice?" ></textarea>
<input type= "Submit" value= "Thank You"/>
</form>

> Key points

1. There must be a onsubmit= "return confirm ()" and "return" is an indispensable word.
2. Self-complete Web page structure.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.