2

My problem is enabling a checkbox in javascript but in disabling my codes is running properly.. i already to change chk1.enabled = checked but its not working..

here's my code:

<script language="javascript" type="text/javascript">

    function ckGrp(){

    var ck_arr = document.getElementsByName('chkRaps');
    var ck = document.getElementsByName('chkPPS');
    if(ck.checked == true){
           ck_arr.disabled = true;
    }else{
          ck_arr.disabled = false;
            }

    }

   </script>

asp.net code:

<td><asp:CheckBox OnClick="ckGrp(); " ID="chkPPS" runat="server" /> &nbsp;<asp:Label ID="Label2" 
        runat="server" Text="Bill Under PPS"></asp:Label>


  <td><asp:CheckBox ID="chkRaps" runat="server" ClientIDMode="Static" Enabled="False" /> &nbsp;<asp:Label ID="Label3" 
        runat="server" Text="Include first billable visit for RAPs"></asp:Label><br/>
        <asp:CheckBox ID="chkTarNumber" runat="server" ClientIDMode="Static" Enabled="False"/> &nbsp;<asp:Label ID="Label4" 
        runat="server" Text="Use Claim Oasis Matching Key as TAR Number"></asp:Label><br/>
        <asp:CheckBox ID="chkPPSMedthod" runat="server" ClientIDMode="Static" Enabled="False" /> &nbsp;<asp:Label ID="Label5" 
        runat="server" Text="Effective 01/01/08 use new PPS Payment Method"></asp:Label><br/>
        <asp:CheckBox ID="chkMTP" runat="server" ClientIDMode="Static" Enabled="False" /> &nbsp;<asp:Label ID="Label6" 
        runat="server" Text="Auto Adjust Claim Amount to Match Total Payment"></asp:Label><br/>
        for differences within +/-<asp:TextBox ID="txtMTP" runat="server" Enabled="False"></asp:TextBox>
3
  • what is checked in your function parameters? Commented Apr 13, 2011 at 7:33
  • As per your code it will set the same state to all your checkbox, so if one is disabled so are the rest. It would be better if you pass in the id to the function and then toggle the states. Commented Apr 13, 2011 at 7:44
  • It would me much easier to post an answer if you give generated HTML code instead of asp.net since it's a client side problem and not server side. Commented Apr 13, 2011 at 7:44

1 Answer 1

3

Change it to:

chk1.disabled = true;

And it'll work. To re-enable, just change the true to false.

Sign up to request clarification or add additional context in comments.

4 Comments

I just tested it. I had a checkbox with id "something". var obj = document.getElementById('something'); obj.disabled = true; Worked perfectly. The "disabled" attribute is a boolean, it accepts true/false values. Are you trying to disable the checkbox when the user checks it? EDIT: Wait, you're trying to ENABLE a textbox, not disable it, right? Why does your code say "chk1.disabled"? Try chk1.Enabled = true. Of course, if the checkbox is already disabled then the user won't be able to check it.
i believe the checked property would be passing the boolean state how does this help ?
It looks like he's trying to enable or disable a checkbox based on it's checkstate. Unless you're controlling the checkstate of the box using another method, the user won't be able to check or uncheck (or interact with) a disabled checkbox.
Ok, you're not getting something. Like neurino said, this is a client side issue, not a server side issue. Like I said, if a checkbox is disabled the user will not be able to check it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.