Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

javascript, checkbox disable other choice with color

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
codewizard2003
Asked:
codewizard2003
  • 2
2 Solutions
 
JayhpotCommented:
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
 
northernchillCommented:
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
 
CleanupPingCommented:
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
 
JayhpotCommented:
i recommend to accept the combination of my answer and that of northernchill's
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now