Monday, October 26, 2009

Play easily turn pattern table is simple- - watch sheet is referred

3, the watch is referred oddly

Since watch sheet is to use the data that collects user input, so, the data that should assure an user is referred to booked place by accurate ground, that is to say, we are referred in watch sheet when, should undertake examining to the data of the user, will can avoid an user to convey data by accident, 2 will can avoid an user to input illegal, perhaps say unqualified data; After certificate of proof, the data that assures an user even submits specific order.

1. Of data examine

Of data examine, have two kinds of programs normally: Client end examines and server end examines. Client end examines, faster, server end examines, opposite for slower, install to ensure complete, use at the same time normally, can avoid an user to be destroyed painstakingly so.
No matter use what means, the principle that data examines is same, once the data of user input does not accord with a regu lation, sign up for a fault, ask the user is inputted afresh, client end examines to often use Javascrip script, the server carries inspect a system and decide, the specific programming that the article does not examine to data undertakes discussing, list a few example to explain merely.

Sample 19: Fill surely, and simple data the kind tests
Take * below must input:
Full name: *
Email: *

Analysis:
  • This exemple added OnSubmit incident to watch sheet, appoint through OnSubmit="return CheckDate()" before referring, must examine through function CheckDate() , if unqualified, return data-in;
  • The function that data examines is as follows:
    < Script >Function CheckDate(){
    / / the data that obtains an inputUserName = Document.RedForm.userName.value;UserEmail = Document.RedForm.userEmail.value;
    / / if do not have input full nameIf (userName=="") {Alert(" inputs full name "); pleaseDocument.RedForm.userName.focus();Return False;
    }else{
    / / if do not have input Email, or Email address mistake (do not contain @) If ((userEmail=="") | | (UserEmail.indexOf("@" )==- 1)) {Alert(" inputs Email address "); afresh pleaseDocument.RedForm.userEmail.focus();Return False;
    }else Return True;
    }
    }
    < / Script >

2. The branch that expresses sheet is referred

When having, watch sheet needs the alternative according to the user, refer different program, how be done?
Detect originally through the foot the choice branch of the user, submit watch sheet to different program thereby, see an example:

Sample 20: Branch is referred
User name: Password:
Company user Individual user

Analysis: What use above all here is the OnSubmit="TwoSubmit(this) of Form "
Next the branch that the basis chooses, will present different program respectively, twoSubmit() function is as follows:

< Script >Function TwoSubmit(form){If (form.Ref[0].checked){It is here 1/0
}else{It is here 2/0
}Form.submit();
}
< / Script >

3. Submit watch sheet with any elements

Have button only or does picture pushbutton ability submit watch sheet? Not be of course, actually, any page elements can submit watch sheet, do not pass, finish originally through the foot, we replace Submit pushbutton with respect to use catenary fetch below:

Sample 21: The fetch that use cha in submits watch sheet
User name: Password: Login Qing Dynasty is empty


Analysis:

Will submit watch sheet through OnClick="document.form.submit()" ; Come with OnClick="document.form.reset()" restoration table is simple, come so, any element can come true submit watch sheet.

 

No comments:

Post a Comment