Ok, I have a set of checkboxes for selecting criteria. For argument's sake, we'll say the data looks like this:
[] Vehicles
[] Unpowered
[] Bicycle
[] Skateboard
[] Powered
[] Two-wheeled
[] Motorcycle
[] Scooter
[] Four-wheeled
etc
The []s represent checkboxes.
Ignoring the obviously contrived nature of this example, the idea is this:
- To start with, only the Vehicle checkbox is visible;
- If the user clicks on the Vehicle checkbox is opsn up the next level (Powered, Unpowered);
- If the user selects Powered it opens up the next level (Two-wheeled, Four-wheeled);
- If the user then unchecks Powered, that level disappears.
Now this is relatively easy to set up with onclick's toggling the display CSS attribute between block and none.
This is currently structured on the page as:
<table>
<tr>
<td><input type="checkbox" onclick="toggle('__Vehicles');"></td>
<td>Vehicles
<table id="__Vehicles">
<tr>
<td><input type="checkbox"></td>
<td>Unpowered
etc
I should point out before someone asks: the reason the checkbox was put in table cell was to control formatting. It made it easy to effectively indent since everything in the next table cell would line up.
It all works fine but the table nesting gets pretty deep. I keep thinking there has to be a better way than this. It has to be able to be easily built dynamically and have good cross-browser support for formatting of the "tree".
I should also mention that jQuery is available. I'm using it for other things.
Suggestions?
Edit: Yes the checkbox styling is important as a couple of comments have noted. Also, I have posted a solution to this, based on the responses I've gotten, as an answer below (too big to add here), just for those curious to see an example.