简体   繁体   中英

HTML troolean form element

What's the best way to simulate a troolean variable with an HTML form?

Specifically, I've got a column that is to be sorted, so it can have three states: unsorted, ascending, and descending. I want to store the state in a form so it is recovered after page submission.

Is there an elegant way of doing this?

EDIT

Javascript is encouraged here. Right now my solution is a hidden input, with a value of 0,1, or 2. The value is changed when the sort button is clicked, and submitted with the form. But perhaps there's a better way?

EDIT

This question has apparently already been asked: Tri-state Check box in HTML? . Voting to close.

使用3个radio盒或带有3个元素的select列表。

Don't go for the magic numbers. As long as the data's going as text over HTTP anyway, you might as well just use values of "ascending", "descending", and "unsorted" or empty.

And a radio button would probably be the thing. Select is overkill for three elements. If you want a different interface, you can use javascript to hide the radio buttons for those with scripting enabled.

I find the way the top checkbox of gmail is working rather intuitive:

  • if no items are selected, the checkbox is empty
  • if at least an item is selected, the checkbox is selected and has an opacity of 0.5
  • if all items are selected, the checkbox is selected with opacity 1

You don't need an image like the referenced page about the Tristate checkbox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM