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)