Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updated show/hide div code - still with errors

Status
Not open for further replies.

kathyc20

Programmer
Mar 7, 2001
96
CA
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>
 
In what way is it not working? What result are you getting and what are you expecting?

In IE the page starts with no default value set on the radio buttons and both text areas showing.
Clicking the left radio button in a group will show the text area but since it is already visible there is no immediate change. Clicking the right radio button of a group hides the text area.

I get no error messages in IE and it appears to work as I would have expected.

At my age I still learn something new every day, but I forget two others.
 
You have no closing HTML tag, an no form element. Perhaps these may be causing you some issues?

However, without knowing what you are seeing (error messages, browser version, etc - all the helpful details you omitted), more tailored help can't really be given.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top