views:

1837

answers:

5

There is no way to have a tri-state check button (yes, no, null) in HTML, right?

Are there any simple tricks or work-arounds without having to render the whole thing by oneself?

+1  A: 

You can use radio groups to achieve that functionality:

<input type="radio" name="choice" value="yes" />Yes
<input type="radio" name="choice" value="No" />No
<input type="radio" name="choice" value="null" />null
Franz
I know that, thanks. :) I am currently using selects, but the form is getting a little cluttered.
Pekka
Well, then what exactly would the third state look like anyways? Just like when the checkbox is disabled? How would you want to trigger that?
Franz
Ah, ok, now I see.
Franz
+1  A: 

You'll need to use javascript/css to fake it.

Try here for an example: http://www.dynamicdrive.com/forums/archive/index.php/t-26322.html

Dan McGrath
+4  A: 

You will definitely need a javascript solution, if you don't want to use radio buttons. Check out this http://www.terminally-incoherent.com/blog/2008/03/24/3-value-checkbox-with-jquery/ example which is using the jQuery library.

x3ro
+1  A: 

It's possible to have HTML form elements disabled -- wouldn't that do? Your users would see it in one of three states, i.e. checked, unchecked, and disabled, which would be greyed out and not clickable. To me, that seems similar to "null" or "not applicable" or whatever you're looking for in that third state.

AmbroseChapel
Very good idea, but I need the user to be able to click it again. I fear that on a disabled checkbox, I will have trouble firing events and so on.
Pekka
+3  A: 

This may help you Tri-State Checkbox using Javascript

priyanka.sarkar
This looks very simple and platform independent, thanks. I will take a look.
Pekka