www.webdeveloper.com
Results 1 to 6 of 6

Thread: Checkbox cancelation: If one checked gray others; visa versa.

  1. #1
    Join Date
    Jun 2009
    Posts
    23

    Checkbox cancelation: If one checked gray others; visa versa.

    See code below:
    If "None" is selected, I need all the other check boxes grayed out.
    If any one (or several/all) of the other check boxes is checked, then "None" grays out. How can I make this work? Using DOM?
    Thanks in advance:

    Here is the code:
    <body>
    <form>
    <p>
    <input type="checkbox" name="Team" value="None" id="None" />
    None<br />
    <br />
    Teams<br />
    <input type="checkbox" name="Teams" value="A" id="A" />
    A<br />
    <input type="checkbox" name="Teams" value="B" id="B" />
    B<br />
    <input type="checkbox" name="Teams" value="C" id="C" />
    C<br />
    </p>
    </form>
    </body>

  2. #2
    Join Date
    Jun 2009
    Location
    West Jordan, Utah
    Posts
    91
    You would use JavaScript. Have you tried anything yet? It is good that each input has an id attribute. You can use this to help you tie up your JavaScript.

    I just made an example of how to do this: http://nathandelanestaging.x10hostin...cellation.html

    Take a look at the source code, it is relatively simple, and I can help you understand any part of it.

  3. #3
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    You actually should be using radio buttons. When radio buttons are named the same, you can only select one in the group:
    Code:
    <body>
    <form>
    <p>
    <input type="radio" name="Team" value="None" id="None" />
    None<br />
    <br />
    Teams<br />
    <input type="radio" name="Teams" value="A" id="A" />
    A<br />
    <input type="radio" name="Teams" value="B" id="B" />
    B<br />
    <input type="radio" name="Teams" value="C" id="C" />
    C<br />
    </p>
    </form>
    </body>

  4. #4
    Join Date
    Jun 2009
    Location
    West Jordan, Utah
    Posts
    91
    If he wants to be able to select multiple options, though then checkboxes are the correct choice. Having them all the same name will return all selected values in a single name too.

  5. #5
    Join Date
    Jun 2009
    Posts
    23

    Half way

    Yes, nathandelane is correct. I need check boxes.
    Also, nathandelane, this is a great start.
    I also need this second part:
    If any one (or several/all) of the other check boxes is checked, then "None" grays out. Without making this too complicated, is this doable??

    Thanks again for the help

  6. #6
    Join Date
    Jun 2009
    Location
    West Jordan, Utah
    Posts
    91
    You just do document.getElementById("checkboxId").checked = false to uncheck the checkboxes when you disable them.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles