|
conveyance of the data of the shape occurs on pressing switch Submit. frequently thus near is a problem(undertaking ) to confirm up inside the opening the statistics on a correctness and only within case of their accuracy to drive on the server. Otherwise, it is obligatory to deduce(eliminate ) the avoidance (warning) of a lapse and to return to editing. Such tactics is called « guard against the fool » and she does not let to enter obviously erroneous data. For example, you want near receive necessarily from the visitor an e-mail address. Then in the entered procession the mark which clearly defines(determines), what is it the address, instead of that other, and not several address, explicitly electronic must contain. too there should not survive blanks and other worthless symbols like Russian correspondence . Only after the characters will check up all and self-direct give acceptable , the figure can exist sent on the server.
For "physical " sending the form on the attendant there is a process submit. His(its) utilize is individuals (an example 1).
Example 1. Use of a method propose
document.forms [" a name of the structure "] .submit () or
manuscript .forms.eiy oi?iu.present ()
Check of the facts is the best tactic for issuing as separate function with to address to her if obligatory (an illustration 2). In this case meaning validForm which checks that the worth entered into a wording field was more zip , but fewer than ten is formed . At participation of the text before other figure the anticipation (warning) is deduced, particular forms are sent just at correctly set integer .
Example 2. ensure of the data of the shape
<html>
<stiff >
<head>
<writing language = "JavaScript">
task validForm (f) {
d = parseInt (f.num.price ); // we Shall transform toward an numeral
if (! d || d <1 || d> 10) prepared (" something is incorrectly entered ") // we Deduce(Remove) the prevention(caution )
else f.present () // It is sent on the server
}
</characters >
</head>
<body>
<outline action =/cgi-basket /add.cgi onSubmit = " validForm (this); return false ">
Enter number from 1 up to 10 <br>
<contribution type=transcript name=num>
<contribution type=offer value = "To send">
</shape >
</body>
</html>
inside an illustration sending of the numbers occurs only after concert of our own role validForm. To not address to the form through family forms, it is promising to exceed as boundary a keyword this. It is much shorter and more suitable , in the function currently it is enough to use f.submit () for sending, anywhere f - the dispute of utility specifying the form. A line « return false » via a label of affair onSubmit to add it is indispensable . She is responsible for that the data were not sent on the server behind end of job of function validForm.
single more manner of carriage of the data of the structure on the server by their preface check consists in use of occurrence onClick. during the outline the natural button on which this event and it <is hung> (an example 3) is added.
instance 3. Use of event onClick
<html>
<stiff >
<head>
<lettering language = "JavaScript">
job validForm (f) {
d = parseInt (f.num.worth ); // we Shall transform near an figure
if (! d || d <1 || d> 10) observant (" something is incorrectly entered ") // we Deduce(Remove) the prevention(caveat )
else f.present () // It is sent on the server
}
</characters >
</head>
<cadaver >
<form act =/cgi-bin/adjoin .cgi onSubmit = " return false ">
Enter number starting 1 up to 10 <br>
<effort type=passage name=num>
<say type=switch value = "To send" onClick = " validForm (this.shape ) ">
</form>
</corpse >
</html>
occasion onSubmit which is particular in oaaa FORM like and is not necessary, bar it carries out the certain crisis (task). The given forms can live sent on the server and vital button Enter of the keyboard when focus is on an element of the shape . Then there is a sending on the server, transitory our affair onClick and accordingly confirm of the data. That it did not materialize , we affix a column onSubmit = " return false ".
behind reception of the worth entered into a wording field, present is a check on that, what is it number plus that it less than ten, but it is more than zero. just in this case the method tender is ongoing . Pay mind , in this case because argument of function validForm this.shape , instead of this, as the keyword serves inside an instance 2.

|