If a radio button is selected, show this

Hi,

I have 3 radio buttons, Test1, Test2, Test3

If radio button Test2 or Test2 are selected, do nothing.

Id radio button Test 3 is selected, show 2 text boxes underneith.

How can I do that?
LVL 3
Computer GuyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

chaitu chaituCommented:
  <script>
  function ex(obj)
  {
	if(obj.id == 'test3')
	{
		document.getElementById("txt").style.display='block';
		
	}
	else
	document.getElementById("txt").style.display='none';

  }
    </script>

 </HEAD>

 <BODY>
TEST1<input type='radio' id='test1' name='rad' onclick='ex(this)'>  
TEST2<input type='radio' id='test2' name='rad' onclick='ex(this)'>  
TEST3<input type='radio' id='test3' name='rad' onclick='ex(this)'>  
<div id='txt' style='display:none'>
<input type='text' id='test4'  >  
<input type='text' id='test5'  >  
</div>
 </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
Bhavesh ShahLead AnalysistCommented:
Hi,

Regards to above code, I will prefer to use value instead of ID.


- Bhavesh
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>

  <script>
  function ex(val)
  {
        if(val == '3')
        {
                document.getElementById("txt").style.display='block';
                
        }
        else
        document.getElementById("txt").style.display='none';

  }
    </script>

 </HEAD>

 <BODY>
TEST1<input type='radio' id='test1' name='rad' value="1" onclick='ex(this.value)'>  
TEST2<input type='radio' id='test2' name='rad' value="2" onclick='ex(this.value)'>  
TEST3<input type='radio' id='test3' name='rad' value="3" onclick='ex(this.value)'>  
<div id='txt' style='display:none'>
<input type='text' id='test4'  >  
<input type='text' id='test5'  >  
</div>

 </BODY>
</HTML>

Open in new window

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
JavaScript

From novice to tech pro — start learning today.