Checkbox jquery enable / disable radioobuttonlist

I have a checkbox and Radiobuttonlist is disabled in the same row of the table and different td and just trying to enable / disable it when I check / uncheck it.

<tr class = "main">
    <td colspan="2">
      <input id="CheckOne" type="checkOne" name="checkOne" />
      <label for="CheckOne">Some Text</label>
    </td>
    <td align="center">
        <table id="RadioButtonListOne" disabled="disabled" title="Choices" border="0">
        <tr>
         <td>
                    <span disabled="disabled">
                    <input id="RadioButtonListOne_0" type="radio" name="RadioButtonListOne" value="Y" disabled="disabled" />
                    <label for="RadioButtonListOne_0">Yes</label></span>
               </td>
               <td>
                    <span disabled="disabled"><input id="RadioButtonListOne_1" type="radio" name="RadioButtonListOne" value="N" disabled="disabled" />
                    <label for="RadioButtonListOne_1">No</label>
                    </span>
               </td>       
           </tr>
        </table>
     </td>
  </tr>

Here is the server side source html:

   <tr class = "main">
       <td colspan="2">
            <asp:CheckBox ID="CheckBoxOne" runat="server" Text="Some Text"/>
       </td>
       <td align="center">
            <asp:RadioButtonList ID="RadioButtonListOne" RepeatDirection="Horizontal">
                  <asp:ListItem Value="Y">Yes asp:ListItem>
                  <asp:ListItem Value="N">No</asp:ListItem>
             </asp:RadioButtonList>
        </td>
   </tr>

For some reason, when I try to do something obvious, i.e.

    $('#<%= CheckBoxOne.ClientID %>').click(function()
    {
        if ($(this).is(":checked"))
        {
             $('#<%= RadioButtonListOne.ClientID%> input:radio').removeAttr('disabled');

        }
        else 
        {
              $('#<%= RadioButtonListOne.ClientID%> input:radio').attr('disabled', 'disabled');
        }
    });

then it does not work, but logically it should be. What am I doing wrong here?

+3
source share
2 answers

why do you include <% = RadioButtonListOne.ClientID% input: radio in your jquery code, also you miss the trailing character>

$('#<%= RadioButtonListOne.ClientID%> input:radio').removeAttr('disabled');

- jquery , ? <% = RadioButtonListOne.ClientID% > php, asp html.erb

if ($(this).attr('checked') == 'checked') 

.is(': checked')

+1

"CheckOne":

<input id="CheckOne" type="checkOne" name="checkOne" />

, ( ) :

$('#<%= CheckOne.ClientID %>').click(function()

:

<input id="<%= CheckOne.ClientID %>" type="checkOne" name="checkOne" />

<input id="CheckOne_<%= CheckOne.ClientID %>" type="checkOne" name="checkOne" />

jQuery,

$('#CheckOne_<%= CheckOne.ClientID %>').click(function()

.

0

Source: https://habr.com/ru/post/1734324/


All Articles