This is a migrated thread and some comments may be shown as answers.

Client side check box checked change inside the radgrid

2 Answers 433 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prassin
Top achievements
Rank 1
Prassin asked on 23 Aug 2012, 07:44 AM
Hi all,

I have a rad grid. rad grid item template having check boxes. and outside the grid (i mean in the form) having 2 text boxes. my requirement is when i check more than one rows inside the grid view  that time 2 text boxes state change to disable. if it is checked one row then text boxes state change to enabled.. i need to work this functionality at client side .... please give me the java script for my requirement..

Thanks and Regards,

Prassin

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Aug 2012, 09:28 AM
Hi Prassin,

Try the following code snippet to achieve your scenario.

ASPX:
<telerik:GridTemplateColumn HeaderText="Checking" UniqueName="check">
  <ItemTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server" onclick="checkboxClicked(event, 'CheckBox1')" />
  </ItemTemplate>
</telerik:GridTemplateColumn>

JS:
<script type="text/javascript">
    function checkboxClicked(e, idFragment) {
        var x = 0;
        var txt1 = document.getElementById("TextBox1");
        var txt2 = document.getElementById("TextBox2");
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            var input = inputs[i];
            if (input.type && input.type == "checkbox") {
                if (input.checked == true) {
                    x++;
                }
            }
        }
        debugger;
        if (x <= 1) {
            txt1.disabled = false;
            txt2.disabled = false;
        }
        else {
            txt1.disabled = true;
            txt2.disabled = true;
        }
    }
</script>

Hope this helps.

Thanks,
Shinu.
0
Prassin
Top achievements
Rank 1
answered on 23 Aug 2012, 12:06 PM
Hi shinu,

the code is working fine but i have one more issue regarding this.i have one other check box in the form.. on page load all controls are to be disabled. and when check the outside check box the same function that checkboxClicked(e, idFragment) need to be run.. function is running fine but my out put is false. and i have modified your code, mentioned that below.

<script type="text/javascript">
    function checkboxClicked(e, idFragment) {
        var x = 0;
        var txt1 = $find('<%= txtRFID.ClientID %>');
        var txt2 = $find('<%= txtSerial.ClientID %>');
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            var input = inputs[i];
            if (input.type && input.type == "checkbox") {
                if (input.checked == true) {
                    x++;
                }
            }
        }
//        debugger;
        if (x == 0) {
            txt1.disable();
            txt2.disable();
               }
        else if (x <= 1) {
            txt1.enable();
            txt2.enable();
            }
        else {
            txt1.disable();
            txt2.disable();
        }
    }
 
</script>

other check box function

 
<script type="text/javascript" language="javascript">
        function EnableControl_5() {
           var txtBox16 = $find('<%= txtRFID.ClientID %>');
            var txtBox17 = $find('<%= txtSerial.ClientID %>');
            var checkbox = document.getElementById('<%= chkOther.ClientID %>');
            if (checkbox.checked) {
                txtBox16.enable();
                txtBox17.enable();
               
            }
else {
                txtBox16.disable();
                txtBox17.disable();
            }
        }
       
    </script>

<asp:CheckBox ID="chkOther" runat="server" onclick="EnableControl_5();"
 Text="Other" Font-Bold="True">
</asp:CheckBox>

my exact requirement is enable the text boxes when click the "chkOther" check box and that time need to check with grid view check boxes too..  if nothing is checked in grid view check box or checked in more than one row inside the check box that time the text boxes should be disable.. if it is checked by one row then text boxes should be enable. 
please help me .. urgent requirement for me.

Regards,

Prassin
Tags
Grid
Asked by
Prassin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Prassin
Top achievements
Rank 1
Share this question
or