Solved

How to disable check boxes on a form using Java Script

Posted on 2011-03-15
2
170 Views
Last Modified: 2012-05-11
This is more of a Java script question. I see "JScript" as a choice of where to post this. I hope JScript is an abbreviation for Java Script.

I have an Asp.net web form with several check boxes on it. If someone checks one check box I need to then disable the other check boxes on the form. If they un-check the check box I need to re-enable the other check boxes on the form. Does anyone know how I can do this using Java Script?
0
Comment
Question by:brgdotnet
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 35137663
0
 
LVL 7

Expert Comment

by:foobarr
ID: 35157573

in markup
<asp:checkbox id="check1" runat="server" />
<asp:checkbox id="check2" runat="server" />
<asp:checkbox id="check3" runat="server" />

in code behind
on page load or wherever you are initializing

check1.attributes.add("onclick", "disableBoxes(this)")
check2.attributes.add("onclick", "disableBoxes(this)")
check3.attributes.add("onclick", "disableBoxes(this)")


in javascript in the markup

function disableBoxes(item)
{
  if (item.id == 'check1'){
       document.getelementbyid("<%= check2.ClientId%>").disabled = true;
       document.getelementbyid("<%= check3.ClientId%>").disabled = true;
  }
  else if (item.id == 'check2') {
    document.getelementbyid("<%= check1.ClientId%>").disabled = true;
       document.getelementbyid("<%= check3.ClientId%>").disabled = true;
  }
 else if (item.id =='check3') {
 {
    document.getelementbyid("<%= check1.ClientId%>").disabled = true;
       document.getelementbyid("<%= check2.ClientId%>").disabled = true;
}
}

0

Featured Post

IT, Stop Being Called Into Every Meeting

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

18 Experts available now in Live!

Get 1:1 Help Now