Web Hosting Talk







View Full Version : Form Validation - Radio button group


mlopezco
02-11-2004, 12:37 PM
Hi. I am a newbie here, so please be nice

I can't figure out why my function isn't working. I am listing the code below, and if anyone can help or has other suggestions, please let me know! - Thanks!!!!!

<head>
<script language="JavaScript" type="text/JavaScript">

function validRadio(formField[i], fieldLabel, num) {
var result = true;

for (i=0, i<num, i++) {

if (!(formField[i].checked)) {
alert('Please select an answer for "' + fieldLabel + '".');
formField.focus();
result = false;
}
}

return result;
}


function validateForm(orientation){

if (!validRadio(orientation.enroll[],"Enrollment Time",3))
return false;

if (!validRadio(orientation.BFscholar[],"Bright Futures recipient",2))
return false;

if (!validRadio(orientation.prog[],"participation in special USF programs",2))
return false;

return true;
}


<FORM id="orientation" name="orientation" method="post" onSubmit="return validateForm(this)" action="mailto:handle@domain.com">


<br>
<input type="radio" name="enroll" id="enroll" value="less">Less than half time (1 - 5 credit hours)

<br>
<input type="radio" name="enroll" id="enroll" value="half">At least half time (6 - 11 credit hours)

<br>
<input type="radio" name="enroll" id="enroll" value="full">Full time (12 or more credit hours)</span>


<table border="0" cellpadding="0" cellspacing="0" width="100%">

<tr class="body">

<td width="25%"><input type="radio" name="BFscholar" id="BFscholar" value="yes">Yes</td>

<td width="25%"><input type="radio" name="BFscholar" id="BFscholar" value="no">No</td>

<td width="50%"> </td>
</tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="body">

<td width="25%"><input type="radio" name="prog" id="prog" value="yes">Yes</td>

<td width="25%"><input type="radio" name="prog" id="prog" value="no">No</td>

<td width="50%"> </td>
</tr>
</table>

Akash
02-11-2004, 02:20 PM
moved to the programming forum :)

ACW
02-11-2004, 02:34 PM
If that is the full code, you should start by closing the head, script and form tags.

mlopezco
02-11-2004, 02:39 PM
No, that isn't the full code - I just copied and pasted sections of it to show the main functions and the input types in the form. I can provide the full code if you need it.

Loon
02-11-2004, 02:54 PM
try this


function doCheck()
{
var Checked = false;
for (i = 0; i < document.orientation.enroll.length; i++) {
if (document.orientation.enroll[i].checked)
Checked = true;
}
if (!Checked) {
alert('no button checked');
return (false);
}
}


should work for you