Hello
I have a form that has 10 questions on it
Each question has a set of Yes/No radio buttons
and a textarea.
If the user clicks Yes, the textarea becomes visible.
If the user click No, the textarea is hidde.
My code seems to be not working the way I want.
What have I done wrong?
Thank you for any help
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
<html xmlns=" xml:lang="en" lang="en">
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function HideShow(obj){
var rad=obj.getElementsByTagName('INPUT');
var area=obj.getElementsByTagName('TEXTAREA')[0];
if (rad[0].checked){ area.style.visibility='visible'; }
else { area.style.visibility='hidden'; }
}
/*]]>*/
</script>
</head>
<body>
<div onclick="HideShow(this);" >
<input type="radio" name="r1" />
<input type="radio" name="r1" />
<textarea rows="2" cols="20" ></textarea>
</div>
<div onclick="HideShow(this);" >
<input type="radio" name="r2" />
<input type="radio" name="r2" />
<textarea rows="2" cols="20" ></textarea>
</div>
</body>
I have a form that has 10 questions on it
Each question has a set of Yes/No radio buttons
and a textarea.
If the user clicks Yes, the textarea becomes visible.
If the user click No, the textarea is hidde.
My code seems to be not working the way I want.
What have I done wrong?
Thank you for any help
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
<html xmlns=" xml:lang="en" lang="en">
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function HideShow(obj){
var rad=obj.getElementsByTagName('INPUT');
var area=obj.getElementsByTagName('TEXTAREA')[0];
if (rad[0].checked){ area.style.visibility='visible'; }
else { area.style.visibility='hidden'; }
}
/*]]>*/
</script>
</head>
<body>
<div onclick="HideShow(this);" >
<input type="radio" name="r1" />
<input type="radio" name="r1" />
<textarea rows="2" cols="20" ></textarea>
</div>
<div onclick="HideShow(this);" >
<input type="radio" name="r2" />
<input type="radio" name="r2" />
<textarea rows="2" cols="20" ></textarea>
</div>
</body>