Use JS to determine if a checkbox has at least one selection

Source: Internet
Author: User
JS we know that if in the ASP, as long as Response.Write Request.Form ("Checkboxname") can determine whether there is a choice of at least one, but must be submitted before you can do so, it is necessary to contact the scripting language Js,vbs

Let's say we have a checkbox called Opthscameratyp, and we write a function to judge

function Chkcheckboxchs (Objnam) {//check if there are at least one item selected for a multiple-selection box
var obj = document.getelementsbyname (Objnam); Access to multiple marquee numbers
var objlen= obj.length; Obtain data length
var Objyn; Do you have a choice
var i;
Objyn=false;
for (i = 0;i< objlen;i++) {
if (obj [i].checked==true) {
objyn= true;
Break
}
}
return Objyn;

}

This is then invoked on the submitting program:

function Oksend ()
{
if (CHKCHSHSC (opthscameratyp) = = False) {
Alert (' Please select at least one! ');
}
Return
}

Because the checkbox has more than one name, so in JS if simple document.all.checkboxNam can not identify exactly which control, must use Document.getelementsbyname, as an array to distinguish them

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.