Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to re-enable check boxes after disabled?

Posted on 2011-09-12
10
Medium Priority
?
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 360 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:Gurvinder Pal Singh
Gurvinder Pal Singh earned 360 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
 
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 480 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

688 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