Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a set of text boxes based on radiobuttonlist selected values i have to disable or enable textboxes using jquery


XML
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
         style="z-index: 1; left: 23px; top: 32px; position: absolute; height: 27px; width: 82px">
         <asp:ListItem Text="Enabled" Value="1"></asp:ListItem>
         <asp:ListItem Text="Disabled" Value="2"></asp:ListItem>
     </asp:RadioButtonList>


XML
<asp:TextBox ID="TextBox1" runat="server"
       style="z-index: 1; left: 24px; top: 114px; position: absolute"></asp:TextBox>
   <asp:TextBox ID="TextBox2" runat="server"
       style="z-index: 1; left: 22px; top: 158px; position: absolute"></asp:TextBox>
   <asp:TextBox ID="TextBox3" runat="server"
       style="z-index: 1; left: 20px; top: 210px; position: absolute"></asp:TextBox>





Posted

I believe you are looking for a JQuery solution, not server-side code. You may need to add classes to the controls involved, since ASP.NET generates its own ID values for server-side controls. If you add classes, your JQuery code would look like this:
$('.toggle').click(function() {
    var disableTextBoxes = ($(this).val() == 2);
    $('.target').prop('disabled', disableTextBoxes);
});

If not, you could base it off the type of the controls, but that's a little dangerous:
$('input[type=radio]').click(function() {
    var disableTextBoxes = ($(this).val() == 2);
    $('input[type=text]').prop('disabled', disableTextBoxes);
});
 
Share this answer
 
Here is a solution..
Script below..
JavaScript
<script src="../jquery-1.4.2.js" type="text/javascript"></script>

    <script type="text/javascript">
    $(document).ready(function()
    {
       $(function()
       {
            var $radBtn = $("table.tbl input:radio");
            $radBtn.click(function()
            {
                var $radChecked = $(':radio:checked');

                if($radChecked.val()==="1")
                {
                    $(".txtbox").removeAttr("disabled");
                }
                else if($radChecked.val()==="2")
                {
                    $(".txtbox").attr("disabled", "disabled");
                }
            });
        });
    });
    </script>

Html below...
HTML
<asp:RadioButtonList ID="RadioButtonList1" class="tbl" runat="server" Style="z-index: 1; left: 23px;
           top: 32px; position: absolute; height: 27px; width: 82px">
           <asp:ListItem Text="Enabled" Value="1" Selected="True"></asp:ListItem>
           <asp:ListItem Text="Disabled" Value="2"></asp:ListItem>
       </asp:RadioButtonList>
       <asp:TextBox ID="TextBox1" runat="server" class="txtbox" Style="z-index: 1; left: 24px;
           top: 114px; position: absolute"></asp:TextBox>
       <asp:TextBox ID="TextBox2" runat="server" class="txtbox" Style="z-index: 1; left: 22px;
           top: 158px; position: absolute"></asp:TextBox>
       <asp:TextBox ID="TextBox3" runat="server" class="txtbox" Style="z-index: 1; left: 20px;
           top: 210px; position: absolute"></asp:TextBox>

Hope you got that you expected..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900