D
Dirk Bollen
Hi,
I'm new to javascript and I want to validate the fields in a html form.
I have written a function to validate my radiobuttons but it seems it
doesn't work.
First I put the form output in a var using : document.getElementById
Than make a functioncall in a nested loop to check all my fields in a form.
The radiobutton check gives an error. It seems that elem.lengt does not
gives the lenght of the array? Putting an alert(elem.length); to check
the output gives 'undefined' message.
What goes wrong?
var gender = document.getElementById('gender');
.......
if(isNumeric(age, "Please enter your age")){
if(isRadio(gender, "Please select a gender")){ ....
//this is the validation function
function isRadio(elem, helperMsg){
//check for array length
alert(elem.length);
for(i=0;i<elem.length;i++){
alert(elem.checked);
if(elem.checked){
return true;
}
}
alert(helperMsg);
elem.focus();
return false;
}
I'm new to javascript and I want to validate the fields in a html form.
I have written a function to validate my radiobuttons but it seems it
doesn't work.
First I put the form output in a var using : document.getElementById
Than make a functioncall in a nested loop to check all my fields in a form.
The radiobutton check gives an error. It seems that elem.lengt does not
gives the lenght of the array? Putting an alert(elem.length); to check
the output gives 'undefined' message.
What goes wrong?
var gender = document.getElementById('gender');
.......
if(isNumeric(age, "Please enter your age")){
if(isRadio(gender, "Please select a gender")){ ....
//this is the validation function
function isRadio(elem, helperMsg){
//check for array length
alert(elem.length);
for(i=0;i<elem.length;i++){
alert(elem.checked);
if(elem.checked){
return true;
}
}
alert(helperMsg);
elem.focus();
return false;
}