Solved

Show textarea if radio button selected

Posted on 2011-02-17
5
680 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now