Considerations for Javascript Form Verification _ javascript tips-js tutorial

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.