mayamanako
Technical User
Hi guys, I've got the code below. Please can you show me how I could make only visible radio buttons required/mandatory. If say, I chose 'Pros', every radio buttons under it should be required/mandatory and everything under 'Testr' are not required/mandatory since they not visible.
Thanks for any help.
Thanks for any help.
Code:
<html>
<head>
<script type="text/javascript" language="javascript"><!--
function VF_refform(){
var theForm = document.forms['refform'];
var rFlg_TestTmr = false;
var rFlg_NonPainfulLrg = false;
var rFlg_PSALevels = false;
var rFlg_ProsFelsMal = false;
var rFlg_condition = false;
var errMsg = "";
var setfocus = "";
for(var r5=0;r5<theForm['TestTmr'].length;r5++){if(theForm['TestTmr'][r5].checked)rFlg_TestTmr=true;}
for(var r4=0;r4<theForm['NonPainfulLrg'].length;r4++){if(theForm['NonPainfulLrg'][r4].checked)rFlg_NonPainfulLrg=true;}
for(var r3=0;r3<theForm['PSALevels'].length;r3++){if(theForm['PSALevels'][r3].checked)rFlg_PSALevels=true;}
for(var r2=0;r2<theForm['ProsFelsMal'].length;r2++){if(theForm['ProsFelsMal'][r2].checked)rFlg_ProsFelsMal=true;}
for(var r0=0;r0<theForm['condition'].length;r0++){if(theForm['condition'][r0].checked)rFlg_condition=true;}
if (!rFlg_TestTmr){
errMsg = "Suspected\?";
setfocus = "['TestTmr'][0]";
}
if (!rFlg_NonPainfulLrg){
errMsg = "Non\-painful\?";
setfocus = "['NonPainfulLrg'][0]";
}
if (!rFlg_PSALevels){
errMsg = "PSA: Yes\/No\?";
setfocus = "['PSALevels'][0]";
}
if (!rFlg_ProsFelsMal){
errMsg = "Pros feels: Yes\/No\?";
setfocus = "['ProsFelsMal'][0]";
}
if (!rFlg_condition){
errMsg = "Please select either \'Pros\', \'Testr\'";
setfocus = "['condition'][0]";
}
if (errMsg != ""){
alert(errMsg);
eval("theForm" + setfocus + ".focus()");
}
else theForm.submit();
}//-->
</script>
</head>
<body>
<div>
<form action="test.html" method='POST' name='refform' id="refform" onSubmit="VF_refform();return false;">
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><h1> </h1></td>
</tr>
<tr>
<td colspan="3">Pros
<input name="condition" type="radio" value="1" id="ProsCheckbox" onClick="myFunction()" /></td>
<td width="200">Testr
<input name="condition" type="radio" value="4" id="TestrCheckbox" onClick="myFunction()" /></td>
</tr>
<tr>
<td colspan="3"> </td>
<td> </td>
</tr>
</table>
<p>
<div id="Pros" style="display:none">
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td> </td>
<td><strong>Yes</strong></td>
<td><strong>No</strong></td>
</tr>
<tr>
<td valign="top">Pros feels</b></td>
<td valign="middle"><input type="radio" name="ProsFelsMal" id="ProsFelsMal" value="1" /></td>
<td valign="middle"><input type="radio" name="ProsFelsMal" id="ProsFelsMal" value="0" /></td>
</tr>
<tr>
<td valign="top">PSA</td>
<td valign="middle"><input type="radio" name="PSALevels" id="PSALevels" value="1" /></td>
<td valign="middle"><input type="radio" name="PSALevels" id="PSALevels" value="0" /></td>
</tr>
</table>
<p> </p>
</div>
<!--Testr-->
<div id="Testr" style="display:none">
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td> </td>
<td><strong>Yes</strong></td>
<td><strong>No</strong></td>
</tr>
<tr>
<td valign="top">Non-pain</td>
<td valign="middle"><input type="radio" name="NonPainfulLrg" id="NonPainfulLrg" value="1" /></td>
<td valign="middle"><input type="radio" name="NonPainfulLrg" id="NonPainfulLrg" value="0" /></td>
</tr>
<tr>
<td valign="top">Suspected</td>
<td valign="middle"><input type="radio" name="TestTmr" id="TestTmr" value="1" /></td>
<td valign="middle"><input type="radio" name="TestTmr" id="TestTmr" value="0" /></td>
</tr>
</table>
<p> </p>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" bgcolor="#E7F3FF"> </p></td>
</tr>
</table>
</div>
<p>
<br />
<input type="submit" value="Submit">
</form>
</div>
</body>
<script language="javascript">
function myFunction() {
var checkBox = document.getElementById("ProsCheckbox");
var text = document.getElementById("Pros");
var checkBox4 = document.getElementById("TestrCheckbox");
var text4 = document.getElementById("Testr");
if (checkBox.checked == true)
{
text.style.display = "block";
}
else
{
text.style.display = "none";
document.getElementById("ProsFelsMal").checked = false;
document.getElementById("PSALevels").checked = false;
}
if (checkBox4.checked == true)
{
text4.style.display = "block";
}
else
{
text4.style.display = "none";
document.getElementById("NonPainfulLrg").checked = false;
document.getElementById("TestTmr").checked = false;
}
}
</script>
</html>