var textboxs = new Array (); Input collection of text type
var radiolist = new Object (); Radio type of input collection, because radio is special, to a set of tests, so here with a Hashtable, according to radio name as key to save all the Radio collection
var radioes; Each name corresponds to the Radio collection
var inputs = Myform.getelementsbytagname ("INPUT"); Take all input below the form
<script> function fn (myform) {var ipt; var textboxs = new Array (); The input set of text type var radiolist = new Object (); Radio type of input collection, because the radio is more special, to a group of detection, so here with a Hashtable, according to radio name as key to save all radio set Var radioes; Each name corresponds to the radio set var inputs = Myform.getelementsbytagname ("INPUT"); Take all input//for (var i=0; i<inputs.length; i++) {IPT = inputs[i] under form; if (Ipt.type = = "Text") {textboxs[textboxs.length] = IPT; //Originally only detects Radiobox, later to add checkbox,//Because the processing mode, as long as the change here can be, but the name is not synchronized modified:)//else if (Ipt.type = = "Radi O "| | Ipt.type = = "checkbox") {radioes = Radiolist[ipt.name]; if (!radioes) {radioes = new Array (); } Radioes[radioes.length] = IPT; Radiolist[ipt.name] = radioes; }//non-null detection//for (Var i=0 i<textboxs.length; i++) {var txt = textboxs[i]; if (txt && txt.value = "") {Alert ("Please fill:" + txt.name); Txt.focus (); return false; }//Traverse all radiobox groups//for (Var radioboxname in radiolist) {radioes = Radiolist[radioboxname]; var chk = false; Whether there is a selected VAR radio; Detects whether the group radio is selected/for (Var j=0 j<radioes.length; J + +) {var radio = radioes[j]; if (radio.checked) {chk = true; Break } if (!CHK)//Not selected {alert ("Please select:" + radioboxname); return false; } return true; } </script> <form method= "POST" action= "onsubmit=" return fn (this); " > <input type= "Text" name= "A1"/> <input type= "text" name= "A2"/> <input type= "Radio" name= "B2"/> <input type= "Radio" name= "B2"/> <input type= "Radio" name= "B2"/> <input type= "text" name= "A3"/> <input type= "Radio" Name= "B1"/> <input type= "Radio" Name= "B1"/><input type= "checkbox" Name= "C1"/> <input type= "checkbox" Name= "C1"/> <input type= "Submit"/> </ form> <form method= "POST" action= "onsubmit=" return fn (this); " > <input type= "Text" name= "A1"/> <input type= "text" name= "A2"/> <input type= "Radio" name= "B2"/> <input type= "Radio" name= "B2"/> <input type= "Radio" name= "B2"/> <input type= "text" name= "A3"/> <input type= "Radio" Name= "B1"/> <input "type= Radio" name= "B1"/> <input type= "checkbox" Name= "C1"/> <input type= "checkbox" Name= "C1"/> <input type= "Submit"/> </form>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]