Solved

Show textarea if radio button selected

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In Angular, how can I programatically fire a function 8 68
Why is this panel heading creating extra space 2 52
jquery auto complete 11 17
replace link with jQuery 4 15
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

832 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