Solved

How to re-enable check boxes after disabled?

Posted on 2011-09-12
10
240 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:sonawanekiran
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks so much
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now