PDA

Click to See Complete Forum and Search --> : form validation - radios


sashabinkie
Feb 13th, 2001, 01:36 PM
can't figure out why the #&@ this doesn't work:

if (!(frmMan.chkDis.checked))
{
alert("Please indicate a Discipline.");
frmMan.chkDis(0).focus();
return false;
}
else
{
return true;
}

Any help would be greatly appreciated!!

whether the radios are selected or not it performs the if and not the else.

Kagey
Feb 13th, 2001, 02:29 PM
if (frmMan.chkDis.checked)
{
return true;
}
else
{
alert("Please indicate a Discipline.");
frmMan.chkDis(0).focus();
return false;
}

how about that?

Feb 13th, 2001, 03:07 PM
Tried inverting this, sama ting it always gives me the else now and not the if. Any other ideas?!!

Feb 13th, 2001, 03:09 PM
Kagey, thanks for the post I tried inverting this, sama ting it always gives me the else now and not the if. Any other ideas?!!

Kagey
Feb 13th, 2001, 05:22 PM
Is this a set of radio buttons, or a checkbox? if it is a set of radio buttons, try this for the if statement:

if (frmMan.chkDis.value = "")
{
return true;
}
else
{
alert("Please indicate a Discipline.");
frmMan.chkDis(0).focus();
return false;
}

Feb 14th, 2001, 07:16 AM
Kagey, thanks again I took your code and cut and pasted it results are the same it now performs the else no matter wether the radio button is checked or not. Inverting this gives me the same result it performs the if statement and never performs the else, thanks.

Mark Sreeves
Feb 14th, 2001, 09:39 AM
it's far from clear waht it is you are trying to do.
Are you testing to make sure that at least one radio button id checked?
If so, this might help:


<HTML>
<HEAD>
<script language=javascript>
function doit()
{
var r

for(i=0;i<=4;i++)
{
r |= document.frm1.radio1(i).checked
}

if(r==0)
alert("Please indicate a Discipline.");

}

</script>
</HEAD>
<BODY>
<form name=frm1>
<INPUT id=radio1 name=radio1 type=radio><BR>
<INPUT id=radio1 name=radio1 type=radio><BR>
<INPUT id=radio1 name=radio1 type=radio><BR>
<INPUT id=radio1 name=radio1 type=radio><BR>
<INPUT id=radio1 name=radio1 type=radio><BR>
<input type=button onclick="doit()">
</form>
</BODY>
</HTML>

Feb 14th, 2001, 12:00 PM
Thanks Mark!!!
Looks like that is exactly what I needed, I went to cnet and found an article from Charity Kahn I redid her code at http://builder.cnet.com/Programming/Kahn/042298 and it got me squared away here thanks alot!!!!
final code looked like this:

function deptChecked(form) {
for (i=0; i<form.chkDis.length; i++) {
if (form.chkDis[i].checked) {
return true;
}
}
return false;
}
function validateForm(form)
{
if (frmMan.frmComment.value == "")
{
alert("Please give us your comments concerning this Lesson.");
return false;
}
if (!deptChecked(form))
{
alert("Please indicate a Discipline.");
return false;
}
else
{
return true;
}
}