Javascript show one of two textareas based on radio button selection

Hi,

I need to show two textareas, but hide one, and show the other based on radio button selection.

So there'll be two radio buttons, and depending on which is selected, it'll show one, or the other textarea.

I have a javascript function already in place which I send the element ID to, and it shows/hides (by display:block, display:none), I don't know if this could be used in some way for this?

Any help would be awesome.

Thanks.
LVL 6
i-CONICAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Hello i-CONICA,

Try this for example :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function changeTA(d) {
		var inputs = d.getElementsByTagName("input");
		for(var i=0; i<inputs.length;i++) {
			if( inputs[i].type == "radio") {
				var radio = inputs[i];
				document.getElementById(radio.value).style.display = radio.checked ? "block" : "none";
			}
		}
	}
</script>
</head>
<body>
	<div class="myradio1">
        <input type="radio" id="radiob1" name="radiob" checked="checked" onchange="changeTA(this.parentNode)" value="ta1" />Show Textarea 1<br />
        <input type="radio" id="radiob2" name="radiob" onchange="changeTA(this.parentNode)" value="ta2"  />Show Textarea 2
    </div>
<br />
<textarea id="ta1" cols="64" rows="16" style="display:block">I'm textarea1</textarea>
<textarea id="ta2" cols="64" rows="16" style="display:none">I'm textarea2</textarea>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
i-CONICAAuthor Commented:
Thank you. :)
0
leakim971PluritechnicianCommented:
Thanks for the points!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.