Hi,

In the following example, all the radio controls have the name attribute set
to "myradio", and the "#offices_checkboxes" part of the document is shown
when the radio with id 'radioOne' is checked. Your example probably didn't
work because of the syntax you used in your attribute selector (no @ symbol
is neccessary in the latest jQuery - this would only work in 1.2 and lower)

$(function(){
  $('#offices_checkboxes').hide();
  $('input:radio[name=myradio]').click(function() {
    if ($(this).attr("id")==='radioOne') {
      $("#offices_checkboxes").show();
    } else {
      $("#offices_checkboxes").hide();
    }
  });
});


Rick Faircloth wrote:
> 
> 
> Just off the top of my head, but may work...
> 
> $(document).ready(function() {
> 
>      $('#offices_checkboxes').hide();
> 
>      $('input:radio[name=radioName]:checked').click(function() {
>           $('#offices_checkboxes').show();
>      });
> 
>      $('input:radio[name=radioName]:not(:checked)'.click(function() {
>           $('#offices_checkboxes').hide();
>      });
> 
> });
> 
> This code makes use of the name of the radio button group, as well.
> 
> hth,
> 
> Rick
> 
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
> Behalf Of mtuller
> Sent: Monday, September 14, 2009 11:14 AM
> To: jQuery (English)
> Subject: [jQuery] Hide/Show based on radio button selected
> 
> 
> I am trying to create a script that will display content based on if a
> radio button is selected, and if the other is selected would hide the
> content. Now, each of these radio buttons are part of a radio group,
> so their names are the same. Most examples show input:radio
> [...@name=item] Since I have 2 items that have the same name, I can't use
> name, so I thought I would try id or value. It isn't working. If I add
> only the show, whenever you select either radio button, it shows, and
> if I add the hide code, it doesn't work at all.
> 
> Here is what I have right now.
> 
>       $(document).ready(function(){
>                 $('#offices_checkboxes').hide();
>                 $("input:rad...@value=1]").click(function() {
>                         $("#offices_checkboxes").show();
>                 });
>                 $("input:rad...@value=0]").click(function() {
>                         $("#offices_checkboxes").hide();
>                 });
> 
>       });
> 
> Anybody have an idea of how I could get this to work?
> 
> 
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Hide-Show-based-on-radio-button-selected-tp25437679s27240p25450984.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to