Solved

How to re-enable check boxes after disabled?

Posted on 2011-09-12
10
241 Views
Last Modified: 2012-05-12
Hello Experts. I have a popup Asp.net web form with Check boxes on it. I am using Java Script. Basically if someone checks one of the check boxes, I need to disable the other remaining check boxes. If someone then Un-Checks the chosen check box, I need to re-enable all of the check boxes again. I figured out how to disable the remaining check boxes after the first one is checked. But how do I re enable all of the other check boxes again? Below is my Java Script method I am using. Attached is the full Asp.net web form which uses the Java Script.

For some reason I am not able to paste the Java Script in Here. Please

see see that attached Java script method named WhichOneChecked

 
JavaScript.txt
0
Comment
Question by:brgdotnet
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36527026
not really something to fix your code but you can start by
replacing : boolean allUnchecked=false;
with : var allUnchecked = false;

in your browser, right click on your page , choose view source and post it here
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 36527271
Yeah, but I still do not have a solution to the problem? I need to know how to re-enable the check boxes. So your answer didn't help me.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36527278
in your browser, right click on your page , choose view source and post it here
0
 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 90 total points
ID: 36527286
Check this..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('input.gridchk:checkbox').click(function(){
          if ($(this).is(':checked')) {
            $('input.gridchk:checkbox').attr('disabled', true);
            $(this).attr('disabled',false);
          }
          else 
            $('input.gridchk:checkbox').attr('disabled', false);
        });
    });
    </script>
</head> 
  <body> 
    <form id="form1" runat="server"> 
    <div> 
    
        <asp:CheckBox runat="server" ID="CheckBox1" onclick=" GoThroughGrid()" Text="One" /> 
    
    </div> 
    <asp:CheckBox ID="CheckBox2" runat="server" Text="Two" /> 
    <p> 
        <asp:CheckBox ID="CheckBox3" runat="server" Text="Three" /> 
    </p> 
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" OnRowDataBound="GridViewPage_OnRowDataBound" > 
        <Columns> 
        <asp:TemplateField HeaderText="Checked" itemstyle-cssclass="sectionContentItemC" ItemStyle-Width="50"> 
            <itemtemplate> 
            <asp:Literal id="literalMember" runat="server" visible="true" /> 
                <asp:Checkbox id="checkboxMember" onclick="WhichOneChecked()" runat="server" visible="true" CssClass="gridchk" /> 
            </itemtemplate> 
        </asp:TemplateField> 
    <asp:BoundField datafield="Name" headertext="Name" HeaderStyle-CssClass="hidden" itemstyle-cssclass="hidden" /> 
<%--        <asp:BoundField datafield="NameId" headertext="Customer" itemstyle-cssclass="sectionContentItem" sortexpression="CustomerName" /> 
--%>        </Columns> 
    </asp:GridView> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AirlinePayableDevConnectionString %>" 
        SelectCommand="SELECT [IsTestMode], [Name] FROM [Root]"> 
    </asp:SqlDataSource> 
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
    </form> 
</body> 
<html>

Open in new window

0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 90 total points
ID: 36527287
at the onchange event of a checkbox, you need to check if this one is unchecked or not. If it is unchecked, then reenable all checkboxes like this

function enableAll()
{
             var grid = document.getElementById("<%= GridView1.ClientID%>");
             var inputs = grid.getElementsByTagName("input");
             for (var counter = 0; counter < inputs.length; counter++)
            {
                 if (inputs[counter].type.toLowerCase() == "checkbox" )
                 {
                     inputs[counter].disabled = false;
                 }
             }
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36527290
My mistake. Ignore above code and use below

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Popup.aspx.cs" Inherits="EnumStuff.Popup" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('input.gridchk:checkbox').click(function(){
          if ($(this).is(':checked')) {
            $('input.gridchk:checkbox').attr('disabled', true);
            $(this).attr('disabled',false);
          }
          else 
            $('input.gridchk:checkbox').attr('disabled', false);
        });
    });
    </script>
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    
        <asp:CheckBox runat="server" ID="CheckBox1" onclick=" GoThroughGrid()" Text="One" /> 
    
    </div> 
    <asp:CheckBox ID="CheckBox2" runat="server" Text="Two" /> 
    <p> 
        <asp:CheckBox ID="CheckBox3" runat="server" Text="Three" /> 
    </p> 
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" OnRowDataBound="GridViewPage_OnRowDataBound" > 
        <Columns> 
        <asp:TemplateField HeaderText="Checked" itemstyle-cssclass="sectionContentItemC" ItemStyle-Width="50"> 
            <itemtemplate> 
            <asp:Literal id="literalMember" runat="server" visible="true" /> 
                <asp:Checkbox id="checkboxMember" onclick="WhichOneChecked()" runat="server" visible="true" CssClass="gridchk" /> 
            </itemtemplate> 
        </asp:TemplateField> 
    <asp:BoundField datafield="Name" headertext="Name" HeaderStyle-CssClass="hidden" itemstyle-cssclass="hidden" /> 
<%--        <asp:BoundField datafield="NameId" headertext="Customer" itemstyle-cssclass="sectionContentItem" sortexpression="CustomerName" /> 
--%>        </Columns> 
    </asp:GridView> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AirlinePayableDevConnectionString %>" 
        SelectCommand="SELECT [IsTestMode], [Name] FROM [Root]"> 
    </asp:SqlDataSource> 
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
    </form> 
</body> 
</html>

Open in new window

0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36527294
Remove onclick="WhichOneChecked()" from <asp:Checkbox id="checkboxMember" onclick="WhichOneChecked()" runat="server" visible="true" CssClass="gridchk" />
0
 
LVL 13

Accepted Solution

by:
ansudhindra earned 120 total points
ID: 36527333
Hi,

Replace your function with the below code. and pass "this" in the onClick event.. like

<asp:Checkbox id="checkboxMember" onclick="WhichOneChecked(this)" runat="server" visible="true" />
 
function WhichOneChecked(ele){
    var strToDisplay ='';
    var inputs = document.getElementById('checkDiv').getElementsByTagName('input');
    if(ele.checked) {
    for(var i=0; i<inputs.length; i++) {
        if (inputs[i].type.toLowerCase() == "checkbox" && inputs[i].checked) 
            strToDisplay += "Checkbox index=" + i + " \n"; 
        else { 
            inputs[i].disabled = true; 
        } 
    }
    
    } else {
    for(var i=0; i<inputs.length; i++) {
        if (inputs[i].type.toLowerCase() == "checkbox") {
            inputs[i].disabled = false; 
        } 
    }
    
    }
}

Open in new window

0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36527341
sorry..
change line number 3 with the below line...

var grid = document.getElementById("<%= GridView1.ClientID%>").getElementsByTagName('input');
0
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 36533970
Thanks so much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now