JavaScript can be used to verify the input data in the HTML form before the data is sent to the server. The typical form data verified by JavaScript includes: Are required items in the Form filled by the user? Is the email address entered by the user valid? Have you entered a valid date? Does the user input text in the data field (numericfield? Javascript form programming:
I. How to search form elements:
1. var oForm = document. getElementById ("Form1 ");
2. var oForm = document. forms [Form1] // search by name;
Ii. Common Features of form fields:
Disabled: Indicates whether a form control is available;
Form attribute: This attribute returns a form containing fields;
Blur (): This method causes the form field to lose focus;
Focus (): This method leads to focus for form fields;
Blur event: This event occurs when the form field loses focus, and then the onblur event handler is executed;
Focus event: This event occurs when the form field gets the focus, and then the onfocus event handler is executed;
Iii. Form submission, reset
Sumbit: oForm sumbit ();
Reset: oForm reset ();
4. Get the value of the text box:
Length otext. value. length;
5. Add element nodes, text nodes, and delete Elements
CreatElement, creatTextNode, remove;
6. select
7. Form Verification best practices:
Must be helpful to users;
Don't be annoying;
If possible, use the HTML function instead of Javascript.
All errors are displayed at one time;
Capture errors earlier;
If you are not sure, do not be too strict;