how about this one? it still validate other fields but the radio button.
------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Contact Us</title>
<SCRIPT language="JavaScript">
//Check the enquiry form is filled in correctly
function CheckForm () {
//Initialise variables
var errorMsg = "";
//Check for a name
if (document.frmEnquiry.name.value == ""){
errorMsg += "\n\tName \t\t- Enter your Name";
}
//Check for comments
if (document.frmEnquiry.comments.value == "") {
errorMsg += "\n\tComments \t- Enter your comments";
}
//Check for gender
if (document.frmEnquiry.gender.checked == true) {
errorMsg += "\n\tGender \t- Select your gender";
}
//If there is aproblem with the form then display an error
if (errorMsg != ""){
msg = "______________________________________________________________\n\n";
msg += "Your enquiry has not been sent because there are problem(s) with the form.\n";
msg += "Please correct the problem(s) and re-submit the form.\n";
msg += "______________________________________________________________\n\n";
msg += "The following field(s) need to be corrected: -\n";
errorMsg += alert(msg + errorMsg + "\n\n");
return false;
}
return true;
}
// -->
</script>
</head>
<body>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<form method="post" name="frmEnquiry" action="send_email.asp" onSubmit="return CheckForm();">
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td>Name* <br>
&nbs p; <input maxlength="30" name="name">
&nbs p; <br>
&nbs p; <input name="gender" type="radio" value="male">
male
<input name="gender" type="radio" value="female">
female * <br>
Comments* <br>
<textarea name="comments" cols="20" rows="2"></textarea>
<br>
<input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
---------------------------
if the above statement doesn't work is there any way I can incroporate the following statement into the current one?
----------------------------
function validateForm (form) {
for (var e = 0; e < form.elements.length; e++) {
var el = form.elements[e];
if (el.type == 'radio') {
var group = form[el.name];
var checked = false;
if (!group.length)
checked = el.checked;
else
for (var r = 0; r < group.length; r++)
if ((checked = group[r].checked))
break;
if (!checked) {
alert('Please check ' + el.name + ' radio button');
el.focus();
return false;
}
}
}
return true;
}
----------------------------
Edited by Lucent - 05 July 2005 at 11:50am