A simple instance of form validation occurs when the text box loses focus:
A lot of forms validation has such a function, that is, when the mouse focus away from the text box, the legitimacy of validation immediately, the following is a simple example of how to implement this function, code examples are as follows:
<Scripttype= "Text/javascript"> functiononblurs () {if(Myform.name.value=="") {alert ("the name must not be empty! "); } Else if(Myform.address.value=="") {alert ("the address must not be empty! "); } } </Script> </P><P></Head><Body><formname= "MyForm"> <Table> <TR> <TD>Name:</TD> <TD><inputtype= "text"name= "Name"/></TD> </TR> <TR> <TD>Address:</TD> <TD><inputtype= "text"name= "Address"/></TD> </TR> </Table></form> </Body></HTML>
The above code copy paste can be tested, the code is very simple, here is not analyzed.
Related reading:
The onblur event can be found in the Onblur event section of JavaScript .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8835
For more information, refer to: http://www.softwhy.com/javascript/
Simple instance of form validation when the text box loses focus