PDA

View Full Version : Select 1 checkbox only


Coral_Lover
10-18-2002, 02:59 AM
Is there any way to allow user to select 1 checkbox only? Or maybe if the user selects more than 1 checkbox, an alertbox will alert him that he has selected more than 1 checkbox.

glenngv
10-18-2002, 03:13 AM
why not just use radio buttons? that's the job of radios.

Coral_Lover
10-18-2002, 03:16 AM
Coz i'm required to use only checkboxes... Hmm.. does that means there's no way to stop the user from selecting multiple checkboxes....

glenngv
10-18-2002, 03:33 AM
of course, there is. but it is just logical to use radio buttons.

adios
10-18-2002, 03:35 AM
<html>
<head>
<title>untitled</title>

<script type="text/javascript" language="javascript">

function like_a_radio(oBox) {
var el, i = 0, f = oBox.form;
while (el = f[i++]) if (el.type == 'checkbox') el.checked = (el == oBox && el.checked);
}

</script>
</head>
<body>
<form>
<input type="checkbox" onclick="like_a_radio(this)"><br>
<input type="checkbox" onclick="like_a_radio(this)"><br>
<input type="checkbox" onclick="like_a_radio(this)"><br>
<input type="checkbox" onclick="like_a_radio(this)"><br>
<input type="checkbox" onclick="like_a_radio(this)">
</form>
</body>
</html>

...not an endorsement. :D

joh6nn
10-18-2002, 07:11 AM
this sounds like an Act of Management, which is similar to an Act of God, except that the former makes less sense, and is more random.

RadarBob
10-18-2002, 07:20 PM
Hmm.. seems like the requirment is to enforce a single selection from a group of choices.

This requirment is directly and fully suppored by radio buttons - without any additional coding!!

Using checkboxes as radio buttons has to bads:
one: You have to write, test, implement, and maintain more code. This is unnecessarily. From a professional software development perspective it's unacceptable.

two: This goes against generally accepted and well understood interface design. Users naturally understand that when they see a group of checkboxes that they can make multiple choices.

If you were a carpenter and I were a lady, would you let me tell you how to build a house? Would you love me anyway?

beetle
10-18-2002, 10:14 PM
Who's requiring you to do so? This guy?

http://www.dilbert.com/comics/dilbert/the_characters/images/icon_the_boss.gif (http://www.webdevelopersjournal.com/columns/pointy-haired_boss.html)
Click it!