How to determine whether multiple elements (Radio,checkbox, etc.) are selected principle Note _ form effects

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.