View Full Version : Problems getting radio buttons to validate

01-28-2008, 04:37 AM
Hi there,

I have a submission form on my site with a number of textboxes, two radio buttons, and a checkbox. When the user submits the form, it calls a Javascript function to go through and make sure everything that is required, has been entered/selected.

I am having troubles getting the radio buttons to validate. For some reason, when it hits that point in the function, it seems to do what it's supposed to (ie., check to make sure one of two two buttons is selected), but then it submits the form without going through the rest of the function.

function contactValidator(formName) {
if (formName.firstname.value == "") {
alert("Please enter your first name.");
return (false);
if (formName.surname.value == "") {
alert("Please enter your surname.");
return (false);
if (formName.senderemail.value == "") {
alert("Please enter your email address.");
return (false);
// Check to make sure a radio button has been selected
var setflag = false;
for (var i = 0; i < formName.freewebmail.length; i ++) {
if (formName.freewebmail[i].checked) {
setflag = true;
if (!setflag) {
alert("Please indicate whether you would like a free webmail account.");
return (false);
if (formName.agreement.checked == false) {
alert("You must check the checkbox to acknowledge your acceptance of the Agreement and submit the form.");
return (false);

return (true);

Any ideas on why it would submit the form without finishing going through the rest of the function?

Thanks for your help.