When submitting a form, you often need to check whether some required fields are empty.
If it is a text box, it is easy to handle. Everyone can write it, but if you encounter multiple raids, checkbox
must select one or more This one is a little more troublesome.
By taking the set of elements of the entire form, we can process it as follows:
var msg="";
var obj="";
var flag=false;
for (var i=0;ivar e = document.frmsignup.elements[i];
if (e.name == 'source'){
if (e.checked==false)
flag= false;
else{
flag=true;
break;
}
}
}
if (!flag) {
msg = "Access source: required Fill in."
obj = "source";
}
This just determines whether multiple radios with name="source" are selected,
For checkbox if you want After judging how many to choose, you only need to add a count to collect the results
If there is a simpler way, I hope you can let me know.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn