?
Solved

javascript, checkbox disable other choice with color

Posted on 2003-03-06
5
Medium Priority
?
247 Views
Last Modified: 2010-04-17
using javascript the setup is this:
i have various diffrent checkbox options in a 3 colum row
i want to disable all other options once the user choses one option.
the row should then turn greyish and all other choices are disabled(they open up again if the user pushes check again)
this should happen in a number of rows

any help would be greatly appreciated
0
Comment
Question by:codewizard2003
[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
  • 2
5 Comments
 

Accepted Solution

by:
Jayhpot earned 200 total points
ID: 8086293
since u hav chosen to use a checkbox, i assume that those checkboxes use different names...
lets say they are check1, check2 and check3...

you may choose to add the javascript in the onClick property of each checkbox or u can create a function that you will call in the onclick property...

either way... you will have the same codes...

set the disabled property of the unchosen checkboxes to false if the chosen checkbox is checked and vise versa...

hence:

<script language="javascript">

   function checkThis(a,b,c){
       //where a is the name of the clicked checkbox
       //and b,c are the names of the unclicked checkbox

       if(eval("document.form1." + a + ".checked==true")){
           eval("document.form1." + b + ".disabled=true")
           eval("document.form1." + c + ".disabled=true")
       }else{
           eval("document.form1." + b + ".disabled=false")
           eval("document.form1." + c + ".disabled=false")
       }
   }
</script>

<form name=form1 action=""...>
  <input type=checkbox name=check1 onClick="checkThis('check1','check2','check3');">...
  <input type=checkbox name=check2 onClick="checkThis('check2','check1','check3');">...
  <input type=checkbox name=check3 onClick="checkThis('check3','check1','check2');">...
0
 
LVL 2

Assisted Solution

by:northernchill
northernchill earned 200 total points
ID: 8087257
The following code will work with any number of checkboxes contained within a form name CheckForm.

Your checkbox tag should read something like:
<INPUT id=checkbox7 type=checkbox name=checkbox7 onclick="return chBoxOnClick(this)">


<Script language="javascript">

var checkCount;
checkCount = 0;
function chBoxOnClick(obj) {

if(document.forms(0).item(obj.id).checked)
   checkCount++;
else
   checkCount--;

if(checkCount < 2)
   enabled = 0;
else
   enabled =1;
     
for(i=0;i<document.forms("CheckForm").length;i++)
{
   if(document.forms(0).item(i).type == "checkbox")
   {
      if(!document.forms(0).item(i).checked)
         document.forms(0).item(i).disabled = enabled;
   }
}
     
}
</script>
0
 

Expert Comment

by:CleanupPing
ID: 9447293
codewizard2003:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 

Expert Comment

by:Jayhpot
ID: 9448711
i recommend to accept the combination of my answer and that of northernchill's
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

770 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