Recently I noticed how yahoo mail select all check box only shows two
states while selecting/un-selecting mails to perform various actions.
So I decided to experiment and create a simple tri-state check box that could display my intermediate state. Below is what I ended up with:
Tri-State Checkbox Demo with dependent checkboxes
It's really simple to use. Here's what you have to do:
- Include the javascript file in your html
- Have a place-holder node (span in my case) to hold the image for the tri-state box
- Place the related checkboxes inside a container, e.g. a div
- Invoke the initTriStateCheckBox(<place holder id>, <container id>, false) function in your html
Standalone Tri-State Checkbox Demo
Here's what you have to do to create a standalone one:
- Include the javascript file in your html
- Have a place-holder node (span in my case) to hold the image for the tri-state box
- Create a hidden field to hold the state of the box
- Invoke the initTriStateCheckBox(<place holder id>, <hidden field id>, true) function in your html
The zip file containing the javascript, images and a sample is available here. It is also a GitHub project set up by Michal Letynski.