My goal is to conceal radio button values upon clicking them, and while I have achieved this in a static context, I am seeking a dynamic solution. Here is an example of my current static implementation:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
<!--
function showDiv( id ) {
document.all.textBox01.style.visibility = 'hidden';
document.all.textBox02.style.visibility = 'hidden';
document.all.textBox01.value = '';
document.all.textBox02.value = '';
document.all[ id ].style.visibility = 'visible';
document.all[ id ].focus();
}
-->
</script>
</head>
<body>
Option 1:
<input type=radio name=radioBtn onClick="showDiv( 'textBox01' );">
<div id=textBox01 style="visibility:hidden">test2</div>
Option 2:
<input type=radio name=radioBtn onClick="showDiv( 'textBox02' );">
<div id=textBox02 style="visibility:hidden">test</div>
</body>
</html>
I am looking for ways to achieve this dynamically and have attempted the following code snippet. Any feedback or suggestions would be greatly appreciated:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
<!--
function change(rad)
{
for(var i = 1; i <= 5; ++i)
{
if(i <= rad.value)
{ document.getElementById("radio" + i).style.visibility = "hidden";
}else
{ document.getElementById("radio" + i).style.value = "";
}
}
}
-->
</script>
</head>
<body>
Option 1:
<input type=radio name=radioBtn onClick="change(this)">
<div id=radio1 style="visibility:hidden">test2</div>
Option 2:
<input type=radio name=radioBtn onClick="change(this)">
<div id=radio2 style="visibility:hidden">test</div>
</body>
</html>