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
Solved

jquery to display different content based on radio selection

Posted on 2011-03-21
3
289 Views
Last Modified: 2012-05-11
I have the following radio buttons:

 

I have a hidden div with a class="options2" that has display:none set. If a user selects option 2, I would like to change it to be changed to display:block.  

What is the best way to accomplish this?
<div class="input-fields-rfq">
	<label>Option 1</label><br />
	<div><input class="end_user" type="radio" name="end_user" value="1" style="width:30px;"></div>
</div>

<div class="input-fields-rfq">
	<label>Option 2</label><br />
	<div><input class="end_user" type="radio" name="end_user" value="2" style="width:30px;"></div>
</div>

<div class="input-fields-rfq">
	<label>Option 3</label><br />
	<div><input class="end_user" type="radio" name="end_user" value="3" style="width:30px;"></div>
</div>

Open in new window

0
Comment
Question by:befidled
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 35180411
$("input[name='end_user']").click(function(){
   if ( $(this).val() == "1" )
   {
      $(".options1").show();
   }
   if ( $(this).val() == "2" )
   {
      $(".options2").show();
   }
   if ( $(this).val() == "3" )
   {
      $(".options3").show();
   }
});
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35180437
or
//this is going to hide the previous option and show the new one
 $("input[name='end_user']").click(function(){
   $(".options1").hide();
   $(".options2").hide();
   $(".options3").hide();
   var value =  $(this).val();
   $(".options" + value ).show();
});

0
 
LVL 1

Author Closing Comment

by:befidled
ID: 35180539
Perfect. Thanks for the quick response!

brian
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

856 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