js| Form Validation | Validation of dynamic forms is a common concern in developing Web applications. Sometimes we have to make sure that some items in the form must be filled in, must be numbers, must be a specified number of digits, and so on, we need to use the form validation, generally we commonly used form validation in 2 ways:
1, write JavaScript or VBScript form validation function, in the client to verify;
2, after the form submitted, using ASP method Request.Form get form input value to judge, and then return the result, this is in the service side to verify;
Both of these methods have their advantages and disadvantages, such as the 1th Way is faster, and usually use the warning box, users can quickly follow the prompts to complete the form, but the disadvantage is that the user's browser must support JavaScript script, or if he closed JavaScript, it would &^* (Xiao Tian has fallen on the ground ^_^) while the 2nd approach is better compatible, the disadvantage is that the speed is slower (submitted to the server, returned) and is inconvenient to use. This is primarily a JavaScript method to verify, of course, if the simultaneous use of 2 ways to verify the most insurance, but (Khan ...). We are tired of the programmers:)
This explains the 2 ways in which form validation is made, and the following is the concept of dynamically generating JavaScript. Why do you want to generate it dynamically? Because this kind of client authentication code is very cumbersome, if every time to write their own really tired ah! Friends using the Dreamweaver or UD may often use form-validated Plug-ins, and the generated code is not artistically available, and many are not used (code redundancy). The field is about generating code that exactly matches the form.
Statement: Small field of JavaScript is not proficient, here just want to talk about dynamic generation of methods, JS Master can completely change their own.
So here we go.
1, let's take a look at a simple JavaScript validation code:
<script language=javascript>
<!--
Power by Xiaotian 2002
function Checksubmit ()
{
if ((document.form1.name.value) = = ")
{
Window.alert (' name must be filled in ');
Document.form1.name.select ();
Document.form1.name.focus ();
return false;
}
Else
return true;
}
-->
</script>
<form name= "Form1" onsubmit= "Javascript:return checksubmit ()" >
<input type= "text" name= "name" >
</form>
This code is the name form item that validates the form Form1 and must be filled in. Here are a few key parts: Form field name, table item name, judgment statement; These are the keys to writing ASP functions below.