A JavaScript instance for detecting form data and a form javascript instance
A JavaScript instance for detecting form data is very simple and practical. If you are interested, you can check it out.
<! DOCTYPE html>
Javascript verification form data problems
Answer
I: I don't understand what you are asking. If only text is displayed but the input box is not displayed, you can use DIV, SPAN, P, and other containers to prompt, or use CSS to remove the external box of the input box;
2. Your function Test has no return value and does not use the test function in onsubmit.
Modify your code. Try again:
<Script language = "javascript">
Function test ()
{
If (document. form1.username. value. length <6 ){
Document. getElementById ("x"). innerHTML = "the user name cannot be less than 6 characters long! "; // X is a layer
Return false;
} Else {
Document. getElementById ("x"). innerHTML = "";
}
If (document. form1.userpass. value. length <6 ){
Document. getElementById ("y"). innerHTML = "the password cannot be less than 6 characters long! ";
Return false;
} Else {
Document. getElementById ("y"). innerHTML = "";
}
}
</Script>
<Form id = "form1" name = "form1" method = "post" action = "baidu.com" onsubmit = "return test ()">
<P>
<Input name = "username" type = "text" id = "username" onblur = "return test ()"/>
<Div id = "x"> </div>
</P>
<P>
<Input name = "userpass" type = "text" id = "userpass" onblur = "return test ()"/>
<Div id = "y"> </div>
</P>
<P>
<Input type = "submit" name = "Submit" value = "submit"/>
</P>
</Form>... the remaining full text>
Javascript detection Form Content
<! ------------------------------------------------------
You can add the function to the page.
Implemented functions:
For multiple groups of radio buttons on the page, automatic group check is performed to ensure that each group has one to be selected. For those with single button followed by a text box, the blank content in the text box is also removed, check whether the text box is valid.
For multiple buttons, check whether one of them is selected within the overall range.
The reason for this design is that the single button is automatically grouped by name, and you can select any name from multiple boxes. Therefore, you can only check multiple selection boxes as a whole.
Feature: you do not have to change any content on your page, you do not have to set the name or ID of each radio button for my code, check work will automatically go to every single button or check box in the form, in addition, you can add or remove single-choice buttons and check boxes without any changes to the Code! Generic!
//////////////////////////////////////// /// // -->
Function ElementsGroup (){
Var group = [];
This. add = function (element ){
Var I;
For (I = group. length-1; I> = 0; I --){
If (group [I] [0]. name = element. name) break;
}
If (I <0 ){
I = group. push ([])-1;
}
Group [I]. push (element );
}
This. getGroup = function (name ){
For (var I = group. length-1; I> = 0; I --){
If (group [I] [0]. name = name) return group [I];
}
Return null;
}
}
Function check (){
Var radios = new ElementsGroup (), checkboxes = [], radioNames = [];
Var elements = event. srcElement. getElementsByTagName (& qu ...... the remaining full text>