Click to See Complete Forum and Search --> : text field required...


Soti
02-10-2003, 01:12 PM
Hello-
I have group of four radio buttons, if the last radio button (other) is chosen I need the text field to ba required. If one of the other radio buttons is chosen then the text field is not required. Can anyone get me started. I've tried several things to the following script but it isn't working:

<!-- Begin

function runFunction()
{
var radios = document.formname.F1
for( x=0; x < radios.length; x++)
if( radios[x].checked) {
var selectedRadio = radios[x].value;
//test it
alert(selectedRadio);
}
}


if(selectedRadio == "other") {
//perform the manditory condition
}
// End -->

Thanks!

Charles
02-10-2003, 01:47 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Form Example</title>
<form action="someScript.pl" name="king" onsubmit="if (this.tut[this.tut.length-1].checked && this.kong.value == '') {alert('Please specify the other.'); this.kong.focus(); return false}">
<div>
<input type="radio" name="tut" value="fee" checked>Fee<br>
<input type="radio" name="tut" value="fie">Fie<br>
<input type="radio" name="tut" value="foe">Foe<br>
<input type="radio" name="tut" value="fum">Fum<br>
<input type="radio" name="tut" value="other" onclick="document.king.kong.focus()"><label for="kong">Other:</label>
<input type="text" name="kong"><br>
<input type="submit">
</form>