You can use the OnSubmit method of the Form form to verify the data in the form or Web page before you submit the form.
OnSubmit The specified method returns True, submits the data, and returns false to not commit the data.
Look directly at the following code:
1 <HTML>2 <Head>3 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />4 </Head>5 <BODY>6 <formAction= "Http://www.baidu.com"onsubmit= "return Tovaild ()">7 <inputtype= "text"ID= "FF">8 <inputtype= "Submit"ID= "Submit"value= "Submit"/>9 </form>Ten </BODY> One <Scriptlanguage= "JavaScript"> A functionTovaild () { - varVal=document.getElementById ("FF"). Value; - alert (val); the if(Val== "can submit"){ - Alert ("validation succeeds, then commits"); - return true; - } + Else{ - Alert ("checksum failed, no commit"); + return false; A } at } - </Script> - </HTML>
in the above page, the form is submitted only if you enter "can submit" in the input box of the id= "FF" , otherwise it will not be submitted.
Validating Html form Forms before submission