need help validating the radio buttons on this form ive tried different functions & different methods on the web but none work. code is this: also for the "Campus" radio buttons you need to be able to select 1 or more & im not sure if what ive done is correct, any help wud be greatly appreciated.

<script type="text/javascript">

function formValidator(){

	var unitnum = document.getElementById('unitnum');
	var unitnam = document.getElementById('unitnam');
	var unitconame = document.getElementById('unitconame');
	var roomnumber = document.getElementById('roomnumber');
	var building = document.getElementById('building');
	var phonenum = document.getElementById('phonenum');

if(isNumeric(unitnum, "Please enter a valid unit number")){
if(lengthtotal(unitnum, 6)){

if(isAlphabet(unitnam, "Please enter only letters for your unit name")){
if(lengthRestriction(unitnam, 1, 50)){

if(isAlphabet(unitconame, "Please enter only letters for your coordinator name")){
if(lengthRestriction(unitconame, 1, 50)){

if(isAlphanumeric(roomnumber, "Numbers and Letters Only for room number")){
if(lengthRestriction(roomnumber, 1, 10)){

if(isAlphanumeric(building, "Numbers and Letters Only for building")){
if(lengthRestriction(building, 1, 15)){


if(isNumeric(phonenum, "Please enter digits for Phone number")){
if(lengthtotal(phonenum, 10)){
							return true;
												
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
	
	return false;
	
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); 
		return true;
	}
	return false;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter " +min+ " and "+max+" characters");
		elem.focus();
		return false;

	}
}

function lengthtotal(elem, total){
	var uInput = elem.value;
	if(uInput.length == total){
		return true;
	}else{
		alert("Please enter " +total+ " digits");
		elem.focus();
		return false;
	}
}

</script>
</head>
<body>
<h1>Unit Information Form</h1>

<h3>Please Fill Out Form</h3>

<p><a href="default.htm"> Back |</a><a href="assessments.htm"> Assessments </a></p>
<fieldset>
<form action="http://tl28serv.uws.edu.au/iwsdinfo/form.asp" name="valform" onsubmit='return formValidator()'  

method="post">
<p>Unit Number:
<input type="text" name="unitnum" /><br /><br />
Unit Name:<input type="text" name="unitnam" /></p>

<p>Campus<br />
<input type="radio" name="campus1" value="campbelltown" /> Campbelltown
<br />
<input type="radio" name="campus2" value="parramatta" /> Parramatta
<br />
<input type="radio" name="campus3" value="penrith" /> Penrith
</p>

<p>Unit Level<br />
<input type="radio" name="unitlvl" value="one" /> 1
<br />
<input type="radio" name="unitlvl" value="two" /> 2
<br />
<input type="radio" name="unitlvl" value="three" /> 3
</p>

<p>Semester<br />
<input type="radio" name="semester" value="Autumn" /> Autumn
<br />
<input type="radio" name="semester" value="Spring" /> Spring<br />
</p>

<p>Unit Coordinator:<br />
Name:
<input type="text" name="unitconame" /><br />Location:<br />
Room Number: <input type="text" name="roomnumber" /><br />
Building: <input type="text" name="building" /><br />
Campus:<br />
<input type="radio" name="unitcocampus" value="campbelltown" /> Campbelltown
<br />
<input type="radio" name="unitcocampus" value="parramatta" /> Parramatta
<br />
<input type="radio" name="unitcocampus" value="penrith" /> Penrith<br />

Phone Number: <input type="text" name="phonenum" /><br />
Email Address: <input type="text" name="email" /><br /><br />
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</p>
</form>
</fieldset>
</body>
</html>

hello, here i have written js code for validating your unit field and radio buttons...
and write remaining code by your self....

<script type="text/javascript">

function formValidator(){

	var d=document.valform;
	if(trimstr(d.unitnum.value)=="")
	 {
	alert("Please enter a valid unit number");
	d.unitnum.focus();return false;
	}
		if(d.campus1.checked==false && d.campus2.checked==false && d.campus3.checked==false) {
		alert("Please check atleast one  radio button!!");
		d.campus1.focus();
	     return false;
	}
  	
}
function trimstr(str) {
	str= this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
</script>

Hi there! Sorry if i post in shanti! Am just here to help! And tnx for the reps' that you gave me.


Too add more functionality and precise handling of your data. Enjoy...

<html>
<head>
<title><!-- Sample --></title>
<script type="text/javascript">
<!--

/* Set the desired parameters to validate your field! 
This is just part of my sample. 
*/

var validEmail = /^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;
var unitNumber = /^[0-9]{3,6}$/;
var unitName = /^[A-Za-z]{3,10}$/;
var roomNumber = /[\w\d]{2,6}/;
var phoneNumber = /^\d{3}[\-]?\d{3}[\-]?\d{4}$/;

/* End of Editing */



//No need to alter the lines below.

function validate()
{ 
 var errors = [];

if ( !validEmail.test( dataform.email.value )) { 
errors[errors.length] = 'You must enter a valid email address!\n'; }

if ( !unitNumber.test( dataform.unitnum.value )) { errors[errors.length] = 'You must enter a valid unit number maximum of 6 charters!\n'; }

if ( !unitName.test( dataform.unitnam.value )) 
{ errors[errors.length] = 'Unit name must between 3 to 10 characters and can only contain letters\'\n'; }

var r1 = dataform.elements['campus'];
var r2 = dataform.elements['unitlvl'];
var r3 = dataform.elements['semester'];
var r4 = dataform.elements['unitcocampus'];

if (( !r1[0].checked ) && ( !r1[1].checked ) && ( !r1[2].checked )) { errors[errors.length] = 'You must atleast select 1 campus on this field!\n';  }

 
if (( !r2[0].checked ) && ( !r2[1].checked ) && ( !r2[2].checked )) { errors[errors.length] = 'You must atleast select 1 unit level on this field!\n';  }

if (( !r3[0].checked ) && ( !r3[1].checked )) { errors[errors.length] = 'You must atleast select 1 semester on this field!\n'; }

if ( !unitName.test( dataform.unitconame.value )) { errors[errors.length] = 'Unit coordinator name must between 3 to 10 characters and can only contain letters\'\n'; }

if (( !r4[0].checked ) && ( !r4[1].checked ) && ( !r4[2].checked )) { errors[errors.length] = 'You must atleast select 1 campus for this unit coordinar on this field!\n';  }

if ( !roomNumber.test( dataform.roomnumber.value )) { errors[errors.length] = 'Room number must between 2 to 6 characters and can only contain letters\' and numbers\n'; }

if ( !unitName.test( dataform.building.value )) 
{ errors[errors.length] = 'Building must between 3 to 10 characters and can only contain letters\'\n'; }

if ( !phoneNumber.test( dataform.phonenum.value )) { errors[errors.length] = 'You must enter a valid phone number!\neg. ( ###-###-#### )\n'; }

if ( errors.length > 0 ) { reportErrors( errors ); return false;
  } return true;
}

function reportErrors( errors )
{ var errorMessage = '\nThere where some problems...\n';
for ( var x = 0; x < errors.length; x++ ) { 
var numberOfError = x + 1;
errorMessage += numberOfError + '. ' + errors[x]; }
alert( errorMessage ) 
}

window.onload = function() {
if ( document.dataform ) {
document.dataform.addEventListener('submit', validate, false ); } 
}
//-->
</script>
</head> 
<body> 
<h1>Unit Information Form</h1> 
<h3>Please Fill Out Form</h3> 
<p>
<a href="default.htm"> Back |</a>&nbsp;
<a href="assessments.htm">Assessments</a>
</p> 
<fieldset>
<legend>Form Data</legend> 
<form name="dataform" action="http://tl28serv.uws.edu.au/iwsdinfo/form.asp" method="post">
<div> 
<label>Unit Number:</label> 
<input type="text" name="unitnum" size="20" />
<br />
<label>Unit Name:</label>
<input type="text" name="unitnam" size="20" value="" /><br /><br />
<span>Campus:</span><br />
<label> 
<input type="radio" name="campus" value="campbelltown" />&nbsp;Campbelltown</label>
<br />
<label> 
<input type="radio" name="campus" value="parramatta" />&nbsp;Parramatta</label>
<br />
<label><input type="radio" name="campus" value="penrith" />&nbsp;Penrith</label><br /><br />
<span>Unit Level</span>
<br /> 
<label><input type="radio" name="unitlvl" value="one" />&nbsp;1</label> 
<br /> 
<label><input type="radio" name="unitlvl" value="two" />&nbsp;2</label> 
<br /> 
<label><input type="radio" name="unitlvl" value="three" />&nbsp;3</label><br /><br /> 
 
<span>Semester</span>
<br /> 
<label><input type="radio" name="semester" value="Autumn" />&nbsp;Autumn</label> 
<br /> 
<label><input type="radio" name="semester" value="Spring" />&nbsp;Spring</label><br /><br />  
<span>Unit Coordinator</span><br /> 
<label>Name:</label><br /> 
<input type="text" name="unitconame" size="20" /><br /><br />
<span>Location</span>
<br /> 
<label>Room Number:</label><br /> 
<input type="text" name="roomnumber" size="20" /><br /> 
<label>Building:</label><br /> 
<input type="text" name="building" size="20" />
<br />
<br />
<span>Campus</span><br /> 
<label><input type="radio" name="unitcocampus" value="campbelltown" />&nbsp;Campbelltown</label>
<br /> 
<label><input type="radio" name="unitcocampus" value="parramatta" />&nbsp;Parramatta</label> 
<br /> 
<label><input type="radio" name="unitcocampus" value="penrith" />&nbsp;Penrith</label><br /><br /> 
<label>Phone Number:</label><br /> 
<input type="text" name="phonenum" /><br /> 
<label>Email Address:</label><br /> 
<input type="text" name="email" size="20" />
<br />
<br /> 
<input type="submit" value="Submit" accesskey="5" />&nbsp;&nbsp;<input type="reset" value="Reset" /> 
</div>
</form> 
</fieldset> 
</body> 
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.