On Jun 11, 2008, at 1:08 PM, Lachlan Hunt wrote:

Christoph Päper wrote:
...
When using
  <input type=checkbox>
or
  <select multiple>
one somtimes wants to limit the number of selected check boxes or options.

Could you provide some examples of some sites that need to apply such limits, and show how people are currently achieving this?

Are there sites that use JavaScript to achieve this now, perhaps by listening for click events on the checkboxes, counting how many are checked and then preventing too many being checked. Or are there sites that count how many are checked onsubmit to ensure there aren't too few or too many?
...

<http://www.drugstore.com/qxc111144_333181_sespider/sample_center/ sample_center.htm> invites you to choose up to three free samples. Choosing more than three is detected after submission, returning you to the same page with an error message.

<http://www.diggerslist.com/register.php> asks you to choose up to three "areas of specialty". This is handled using three option menus containing exactly the same options. Choosing the same option twice or thrice, though probably a human error, is accepted without complaint.

<http://www.bbc.co.uk/wales/livinginwales/nameyourhouse/housename.swf> invites you to specify up to three features of your house. The design annoyingly requires each choice to be confirmed separately followed by a "Would you like to choose another?" alert. It is implemented using Flash, though it would be easy to implement in HTML and JavaScript.

<http://www.oup.com/elt/global/products/goodgrammarbook/menu/apretest/> invites you to select up to five topics of English grammar using checkboxes. Whenever five checkboxes are checked, all unchecked checkboxes are disabled. It is implemented using Flash, though again it would be easy to implement in HTML and JavaScript.

<http://members.c-span.org/Subscribe.aspx> requires you to choose at least one of two alert types, and at least one of five programmes. In both cases, selecting zero is detected after submission, returning you to the same page with an error message.

<http://www.nicelabel.com/Products/Product-Selector> invites you to select at least one of four label types. Submitting the form with zero selected is detected using a script that reveals the text "Please, choose at least one option". This text was there all the time, just hidden, so would be confusing in UAs that disregarded CSS.

A browser supplied with min= and max= attribute values could provide more consistent and timely error prevention in all these cases. One challenge would be conveying the minimum and maximum requirement where the form's initial selection was outside the allowed range (most commonly where a minimum is required but no options are selected by default); without having the site author's knowledge about where an error message can sensibly be inserted in the page, a browser might need to use tooltips or help balloons instead.

Cheers
--
Matthew Paul Thomas
http://mpt.net.nz/

---AV & Spam Filtering by M+Guardian - Risk Free Email (TM)---

Reply via email to