views:

396

answers:

2
<tr>
   <td align="left">
         <input type="radio" name="radio_1" value="1" />Public
         <input type="radio" name="radio_1" value="2" />Not Public
         <input type="radio" name="radio_1" value="3" />Confidential
   </td>
</tr>
<tr>
   <td align="left">
         <input type="radio" name="radio_2" value="1" />Public
         <input type="radio" name="radio_2" value="2" />Not Public
         <input type="radio" name="radio_2" value="3" />Confidential
   </td>
</tr>
<tr>
   <td align="left">
         <input type="radio" name="radio_3" value="1" />Public
         <input type="radio" name="radio_3" value="2" />Not Public
         <input type="radio" name="radio_3" value="3" />Confidential
   </td>
</tr>

hi,

If i select first option in the first row of radio buttons. In the second row i don't check the first option because first option is already checked in the first row.. I need a jquery validation for this

Please someone help me!

A: 

I suppose the easiest way would be to check for the click action in jquery

so you would have..

$(input[type=radio]).click(function() {
  //Store THIS object
  var $this = $(this);

  //Get the id of this radio button
  var $id = $this.attr('id');

  //If radio button is selected
  if($this.is(':selected') {  

    //Disable all other radio buttons with this id.
    $('#' + $id).changeClass("disabled");

  } else {
    //Else it is being unselected, so enable radio buttons with id.
    $('#' + $id).changeClass("enabled");
  }
};

A few points..

  • Im not sure if if($this.is(':selected') is the best way to check on radio buttons, but a similar method works with check boxes
  • Instead of changing the class you may want to jsut alter an attribute or a css propterty.
cast01
+1  A: 

You need to rearrange the names/values of the radio buttons.

<tr>
   <td align="left">
         <input type="radio" name="radio_1" value="1" />Public
         <input type="radio" name="radio_2" value="1" />Not Public
         <input type="radio" name="radio_3" value="1" />Confidential
   </td>
</tr>
<tr>
   <td align="left">
         <input type="radio" name="radio_1" value="2" />Public
         <input type="radio" name="radio_2" value="2" />Not Public
         <input type="radio" name="radio_3" value="2" />Confidential
   </td>
</tr>
<tr>
   <td align="left">
         <input type="radio" name="radio_1" value="3" />Public
         <input type="radio" name="radio_2" value="3" />Not Public
         <input type="radio" name="radio_3" value="3" />Confidential
   </td>
</tr>

The value now denotes the order instead of the name. This is much easier. No need for JS validation.

BalusC
awesome!! that's the spirit
Alexander Taran