Javascript form validation considerations
- 2020-03-30 04:03:23
- OfStack
Javascript form programming:
I. search method of form elements:
1. Var oForm = document. GetElementById (" Form1 ");
Var oForm=document.forms[Form1]//
Ii. Common features of form fields:
Disabled: this property indicates whether a form control is available.
Form property: this property returns the form containing the fields;
Blur (): this method causes the form field to lose focus;
Focus () : this method causes the form field to get focus;
Blur event: this event occurs when a form field loses focus, followed by onblur event handler;
Focus event: this event occurs when the form field gets focus, followed by the onfocus event handler;
Three: form submission, reset
Sumbit: OForm sumbit ();
Reset: OForm reset ();
Get the value of the text box:
Length Otext. Value. Length;
Five: add element node, text node, delete element
CreatElement, creatTextNode, remove;
Six: select the value of the check box: select
Seven: best practices for form validation:
Must be helpful to the user;
Don't be annoying;
Replace Javascript with HTML functionality whenever possible
Display all errors at once;
Catch errors early;
Don't be too strict if in doubt;