|
problem with radio button in form validation
I have a multi-field that consist of text, radio button and select field but the main prob is when it goes to radio button and i tried to submit it, the validation for radio button doesn't work... So can you check this coding and what is wrong with it???
<SCRIPT LANGUAGE=JAVASCRIPT>
function validate(form) {
//Data validation using object names to
// reference objects
if (form.user_name.value == "") {
alert("You must enter a User Name");
form.user_name.focus()
return false;
}
if (form.password.value == "") {
alert("You must enter a Password");
form.password.focus()
return false;
}
if (form.password.value != form.confirmpassword.value) {
alert("Password and Password Confirmation Did Not Match");
form.confirmpassword.focus()
return false;
}
if (form.first.value == "") {
alert("You must enter a First Name");
form.first.focus()
return false;
}
if (form.last.value == "") {
alert("You must enter a Last Name");
form.last.focus()
return false;
}
if (form.age.value == "") {
alert("You must enter Age");
form.age.focus()
return false;
}
if (form.dob.value == "") {
alert("You must enter your birth date");
form.dob.focus()
return false;
}
//coding for radio button
function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;
// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter <form.gender.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (form.gender[counter].checked)
radio_choice = true;
}
if (!radio_choice)
{
// If there were no selections made display an alert box
alert("Please select a Gender.")
return (false);
}
return (true);
}
</script>
|