• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

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?
0
Computer Guy
Asked:
Computer Guy
2 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now