Thursday, 22 August 2013

Validating radio elements in a form not by the name

Validating radio elements in a form not by the name

i have to validate the radio elements in a form with javascript, but i
cannot do it by the name (getElementByName), for many reasons that it's
long explaining. Actually i'm trying to validate them symply with:
for (var i=0; i<document.forms[0].elements.length; i++){
element = document.forms[0].elements[i];
if(element.checked){}
else {alert("whatever");}
}
But in the form there is an element which is a button, and it counts linke
a not checked element and always returns the else statement. So this code
is not useful to validate the form. Is there a manner to select only the
radio elements of a form? Like type[radio] or something like that? Thanks
in advance for your time. Agnese

No comments:

Post a Comment