user1338194
user1338194

Reputation: 267

validating checkbox limit javascript

var cbx = document.getElementById('ModelFilter').getElementsByTagName('input');
var ArrCB_l=cbx.length;

while(ArrCB_l--){
    var CB=ArrCB[ArrCB_l];
    CB.checked()==True;
    return 1
}
return 0

Can anyone tell me what is wrong with this? I know the first line is the correct input as I am using it elsewhere for the same checkboxes, however this won't work? I am trying to make sure there is at least one checkbox checked. This function is called with an onsubmit event.

Upvotes: 0

Views: 181

Answers (4)

Michael Besteck
Michael Besteck

Reputation: 2423

while(ArrCB_1) {
    if(cbx[--ArrCB_1].checked) {
        return true;
    }
}
return false;

Upvotes: 1

Mehmet
Mehmet

Reputation: 1874

document.getElementById('ModelFilter').getElementsByTagName('input');

this code returns all inputs(text,button,radio etc)

use

document.getElementById('ModelFilter').getElementsByTagName("input")[ArrCB_l].type == "checkbox"

Upvotes: 0

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123377

while(ArrCB_l--){
    if (cbx[ArrCB_l].checked) {
       return true;
    }
}
return false;

your collection is cbx and not ArrCB, and checked is not a method but it's an attribute/property of the element

Upvotes: 0

robertboloc
robertboloc

Reputation: 169

.checked() should be just .checked

Upvotes: 1

Related Questions