When submitting a form, it is often necessary to determine whether some required fields are empty,
If it's a text box it's good to do, but if you encounter multiple Raido,checkbox
One or more must be a little more troublesome.
By taking a collection of elements from the entire form, we can do the following:
Copy Code code as follows:
var msg= "";
var obj= "";
var Flag=false;
for (Var i=0;i<document.frmsignup.elements.length;i++) {
var e = document.frmsignup.elements[i];
if (e.name = = ' source ') {
if (E.checked==false)
Flag=false;
else{
Flag=true;
Break
}
}
}
if (!flag) {
msg = "Access Source: must be filled in."
obj = "source";
}
This just determines whether multiple radio of the name= "source" have been selected,
For a checkbox if you decide to select a few, you just need to add a count to collect the results.
If there is a simpler way, hope to be able to tell.