[Javascript] FW: greying out checkboxes

Kipp Spanbauer Kipp.Spanbauer at sas.com
Fri Dec 20 10:44:07 CST 2002


Philip:

Here's the code that I used:

<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original:  Mike Elkins (m_c_elkins at hotmail.com) -->
<!-- Modified:  Kipp Spanbauer (kippspanbauer at yahoo.com) -->
<!-- Modifiied script will disable checkboxes that are unused. -->

<!-- Begin
  function selectivecheck(field, myselection)
    {
      var fieldid;
      var pos;
      var criteria;
      var strng;
      strng = myselection.value;
      for (i=0; i<field.length; i++)
        {
          if (strng=="all")
            {
            field[i].checked = true;
            field[i].disabled = false;
            }
          else
            {
              fieldid = field[i].id;
              pos = strng.substring(0,1);
              criteria = strng.substring(1,2);  //this gets the information we want to evaluate
              if (fieldid.substring(pos,pos+1)==criteria)
                {
                  field[i].checked = true;
                  field[i].disabled = false;
                }
              else
                {
                  field[i].checked = false; //you could leave this out if you don't want to clear the check boxes
                  field[i].disabled = true;
                }
            }
        }
    }
//  End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->

<BODY>

<form>
<table align="center">
<tr><td>
<!--Load each ID with a string that will be parsed later -->
  <input id=a1 type=checkbox name=list value="1">Group A SubGroup 1<br>
  <input id=a2 type=checkbox name=list value="2">Group A SubGroup 2<br>
  <input id=b1 type=checkbox name=list value="3">Group B SubGroup 1<br>
  <input id=b2 type=checkbox name=list value="4">Group B SubGroup 2<br>
  <input id=c1 type=checkbox name=list value="5">Group C SubGroup 1<br>
  <input id=c2 type=checkbox name=list value="6">Group C SubGroup 2<br>
<!--Set your option values that contain a position and then the criteria-->
<p>
Group Selection: <select size="1" name="mycombobox" onChange="selectivecheck(this.form.list, this.form.mycombobox);">
  <option value="all">All Groups</option>
  <option value="0a ">Group A</option>
  <option value="0b ">Group B</option>
  <option value="0c ">Group C</option>
  <option value="11 ">SubGroup 1</option>
  <option value="12 ">SubGroup 2</option>
</select>
<br>
<div align="center">
<input type="button" value="Select Group" onclick="selectivecheck(this.form.list, this.form.mycombobox)">
</div>
</td></tr>
</table>
</form>


<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
</BODY></HTML>


Good luck,
Kipp Spanbauer
kipp.spanbauer at sas.com





-----Original Message-----
From:	Kipp Spanbauer
Sent:	Fri 12/20/2002 9:55 AM
To:	phumes1 at rogers.com
Cc:	phil.humeniuk at rogers.com; javascript at LaTech.edu
Subject:	greying out checkboxes
Philip:

I had the same question that you did regarding greying out javascript checkboxes and found my answer on a macromedia website:  http://www.macromedia.com/v1/documents/hs4/html_reference/Forms/input.htm

Basically, all you need is the word "DISABLED" in the along with the INPUT tag.  Example:

<input class="formbuttons" DISABLED type="checkbox" name="select" value="mcp">User 
must change password at next login<br>

That should do it for you.

I found your message at:
https://lists.latech.edu/pipermail/javascript/2002-April/003356.html

Thanks,
Kipp Spanbauer
kipp.spanbauer at sas.com




============================================================

Philip Humeniuk's message read as follows:

Hi,

I have the following input boxes in my index.htm file. What I would like to 
happen is if the user checks the box "User must change password at next 
login" I want the "User cannot change password" and "Password never 
expires" checkboxes grayed out and possibly the text also so they cannot 
check those. The only other option to check would be the "Account is disabled"

Can this be easilty done with JS?



<input class="formbuttons" type="checkbox" name="select" value="mcp">User 
must change password at next login<br>
<input class="formbuttons" type="checkbox" name="select" value="ccp">User 
cannot change password<br>
<input class="formbuttons" type="checkbox" name="select" 
value="pne">Password never expires<br>
<input class="formbuttons" type="checkbox" name="select" value="ad">Account 
is disabled










More information about the Javascript mailing list