Home > Web Front-end > JS Tutorial > body text

Explanation of the principle of determining whether multiple elements (RADIO, CHECKBOX, etc.) are selected_Form special effects

WBOY
Release: 2016-05-16 18:55:49
Original
1034 people have browsed it

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:

Copy code The code is 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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template