Looping through Checkboxes using Javascript

后端 未结 3 1117
说谎
说谎 2021-01-27 12:35

I tried using javascript samples that I found here and other places. The problem is that I am using a Table control working at the server, so the javascript I was using does not

3条回答
  •  野性不改
    2021-01-27 13:01

    You need something like this

    var pass = true;
    
    for (var i = 0; i < form.elements.length; i++ ) 
    {
        if (form.elements[i].type == 'checkbox')
        {
            if (form.elements[i].checked == false)
            {
                pass = false;
            }
        }
    }
    
    if(!pass)
    {
        alert ('You must check all the checkboxes!');
    }
    
    return pass;
    

    Hope this helps.

提交回复
热议问题