Home >Web Front-end >JS Tutorial >Things to pay attention to in Javascript form validation_javascript tips
Javascript form programming:
1. How to find form elements:
1.var oForm=document.getElementById("Form1");
2.var oForm=document.forms[Form1]//Search by name;
2. Common characteristics of form fields:
disabled: This attribute is used to indicate whether a form control is available;
form attribute: This attribute returns the form containing fields;
blur(): This method causes the form field to lose focus;
focus(): This method causes the form field to gain focus;
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 gains focus, and then the onfocus event handler is executed;
Three: Form submission, reset
sumbit: oForm sumbit();
reset: oForm reset();
4. Get the value of the text box:
length otext.value.length;
Five: Add element nodes, text nodes, delete elements
creatElement, creatTextNode, remove;
6: Check the value of the check box: select
Seven: Best practices for form validation:
Must be helpful to users;
Don’t be annoying;
Use HTML functionality instead of Javascript whenever possible
Show all errors at once;
Catch errors early;
Don’t be too strict if you are not sure;