Solved

Show textarea if radio button selected

Posted on 2011-02-17
5
695 Views
Last Modified: 2012-05-11
I want to show a text box if a radio button is selected.  I have the following radio buttons:

<input type="radio" name="resolved" id="Yes" value="Y" />
<input type="radio" name="resolved" id="No" value="N" />

And the following code which is not working:

<script type="text/javascript">
<!--
$('input[name=resolved]').change(function() {
if($(this).val() == "Y") {
$('#resolution').show();
} else {
 $('#resolution').hide();    
 }
 });
 //-->
</script>

Any help appreciated!
0
Comment
Question by:peterbrowne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34922866
using :

		$("input[type='radio'][name='resolved']").click(function() {
			if( $(this).attr("value") == "N" ) {
				$("#ta").show();
			}
			else {
				$("#ta").hide();
			}
		});

Open in new window


test page :
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Show Enable - Hide Disable Based on radio Selection</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("input[type='radio'][name='resolved']").click(function() {
			if( $(this).attr("value") == "N" ) {
				$("#ta").show();
			}
			else {
				$("#ta").hide();
			}
		});
	});
</script>
</head>
<body>
<input type="radio" name="resolved" id="Yes" value="Y" />Yes<br />
<input type="radio" name="resolved" id="No" value="N" checked />No<br />
<textarea id="ta" cols="20" rows="5"></textarea>
</body>
</html>

Open in new window

0
 

Author Comment

by:peterbrowne
ID: 34922917
Thanks, how do I have the text area hidden by default.  I've changed your code as follows:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
      $(document).ready(function() {
            $("input[type='radio'][name='resolved']").click(function() {
                  if( $(this).attr("value") == "Y" ) {
                        $("#resolution").show();
                  }
                  else {
                        $("#resolution").hide();
                  }
            });
      });
</script>
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34922925
with jquery :

      $(document).ready(function() {
            $("#ta").hide();
            $("input[type='radio'][name='resolved']").click(function() {
...

Open in new window


with style :)  

<textarea id="ta" cols="20" rows="5" style="display:none"></textarea>

Open in new window

0
 

Author Comment

by:peterbrowne
ID: 34922943
Well that was easy...

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
      $(document).ready(function() {
            $("#resolution").hide();
            $("input[type='radio'][name='resolved']").click(function() {
                  if( $(this).attr("value") == "Y" ) {
                        $("#resolution").show();
                  }
                  else {
                        $("#resolution").hide();
                  }
            });
      });
</script>
0
 

Author Closing Comment

by:peterbrowne
ID: 34922945
Many thanks!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery Scroll To Top 5 52
jQuery Toggle & Anchor Links 5 55
TypeError jquery issues with site - CSS conflicts 3 27
JQuery DataTable Functionality 8 17
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question