A user is offered a number of choices. A user must select one or more choices. A collection of radio buttons allows for only one choice. A collection of checkboxes allows zero or more choices.
Is there some CSS I can add to a collection of checkboxes that stops all
of them from being unselected? So if the user is unselecting checkboxes
the last selected checkbox can't be unselected. I don't want to use JavaScript to tell the user to select a check box (if no checkbox is selected).
Perhaps there's some other UI component is more appropriate?
Hmm, a search seems to indicate that this is a common problem with only
a code-based solution :-(
Is there some CSS I can add to a collection of checkboxes that stops all
of them from being unselected? So if the user is unselecting checkboxes
the last selected checkbox can't be unselected.
In article <Q8mdnTXeL8q26FTCnZ2dnUU7-d_NnZ2d@westnet.com.au>,
Andrew Poulos <ap_prog@hotmail.com> wrote:
Is there some CSS I can add to a collection of checkboxes that stops all
of them from being unselected? So if the user is unselecting checkboxes
the last selected checkbox can't be unselected.
It's too late, I won't try to test it, but I think if you place all your checkboxes one after the other, as siblings, and the submit button as the last sibling, you can use the :checked pseudo-class to hide and unhide the submit button so they can't submit until at least one box is checked.
#submit-button {display: none;}
.box:checked ~ #submit-button {display: inline-block;}
Something like that.
Pierre
In article <Q8mdnTXeL8q26FTCnZ2dnUU7-d_NnZ2d@westnet.com.au>,
Andrew Poulos <ap_prog@hotmail.com> wrote:
Is there some CSS I can add to a collection of checkboxes that stops all
of them from being unselected? So if the user is unselecting checkboxes
the last selected checkbox can't be unselected.
It's too late, I won't try to test it, but I think if you place all your >checkboxes one after the other, as siblings, and the submit button as the >last sibling, you can use the :checked pseudo-class to hide and unhide the >submit button so they can't submit until at least one box is checked.
In article <rqcoh3$7na$1@reader1.panix.com>,
Pierre Jelenc <rcpj@panix.com> wrote:
In article <Q8mdnTXeL8q26FTCnZ2dnUU7-d_NnZ2d@westnet.com.au>,
Andrew Poulos <ap_prog@hotmail.com> wrote:
Is there some CSS I can add to a collection of checkboxes that stops all >>> of them from being unselected? So if the user is unselecting checkboxes
the last selected checkbox can't be unselected.
It's too late, I won't try to test it, but I think if you place all your
checkboxes one after the other, as siblings, and the submit button as the
last sibling, you can use the :checked pseudo-class to hide and unhide the >> submit button so they can't submit until at least one box is checked.
Here it is:
<html>
<head>
<style>
#submit {display:none;}
#info {display:inline;}
input:checked ~ #submit {display:inline;}
input:checked ~ #info {display:none;}
</style>
</head>
<body>
<form action="#">
1:<input type="checkbox" name="test1" value="1">—
2:<input type="checkbox" name="test2" value="2">—
3:<input type="checkbox" name="test3" value="3"><br>
<input type="submit" id="submit">
<span id="info">chose at least one</span>
</form>
</body></html>
On 4/12/2020 10:30 am, Andrew Poulos wrote:
A user is offered a number of choices. A user must select one or
more choices. A collection of radio buttons allows for only one
choice. A collection of checkboxes allows zero or more choices.
Is there some CSS I can add to a collection of checkboxes that
stops all of them from being unselected? So if the user is
unselecting checkboxes the last selected checkbox can't be
unselected. I don't want to use JavaScript to tell the user to
select a check box (if no checkbox is selected).
Perhaps there's some other UI component is more appropriate?
Hmm, a search seems to indicate that this is a common problem with
only a code-based solution :-(
Too hard for me to solve with CSS so I went for some JavaScript
that checks the number of checked checkboxes and rechecks the last
checked checkbox (if the user unchecks it.)
Still it's an "ugly" thing to do (to have a checkbox behave
differently from the norm).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 16:09:14 |
Calls: | 6,646 |
Calls today: | 1 |
Files: | 12,190 |
Messages: | 5,327,107 |