Make checkboxes act like radiobuttons?

C

Chuck W.

Is there a way with javascript to make a series of checkboxes behave
like radio buttons, such that if someone attempts to check more than
one, they would get a pop-up alert "can't do that" ?

Thanks,

Chuck
 
T

Thomas 'PointedEars' Lahn

Chuck said:
Is there a way with javascript to make a series of checkboxes behave
like radio buttons, such that if someone attempts to check more than
one, they would get a pop-up alert "can't do that" ?

Yes, please show your approach that is not working.


PointedEars
 
C

Chuck W.

See below. For various serverside/database reasons the names of these
elements needs to be different:

<form action="index.cfm" method="post" name="myform">
<table border=0>
<tr valign=top><td>
Clinic (new LYL player): </td><td >&nbsp;</td> <td><input
type=checkbox name=fallclinic value="60"> $60.00</td></tr>
<tr valign=top><td>
Fall Ball (returning LYL player): </td> <td ><img
src="/images/trans.gif" border=0 width=270 height=1></td><td><input
type=checkbox name=fallball value="60"> $60.00</td></tr></table>

</td>
</tr>

<tr valign=top>
<td><strong>Spring</strong><br>
<font color=red size=-2>(choose ONE only)</font></td> <td align=left>

<table border=0 cellpadding="7" cellspacing="0">
<tr valign=top><td>In house clinic </td><td><img
src="/images/trans.gif" border=0 width=190 height=1> </td><td><input
type=checkbox name=springclinic value="70"> $70.00</td></tr>
<tr valign=top><td>League (1st and 2nd graders only):
</td><td>&nbsp;</td><td>
<input type=checkbox name=springleague value="70">
$70.00</td></td></tr>
</table>
<input type=submit value="submit">
</form>
 
M

Matt Kruse

Chuck said:
Is there a way with javascript to make a series of checkboxes behave
like radio buttons, such that if someone attempts to check more than
one, they would get a pop-up alert "can't do that" ?

Why not make them radio buttons then?

I have a lib called CheckboxGroup that will allow you to treat a bunch of
checkboxes as a group and limit the number of them that can be checked. It
might help you out:
http://www.JavascriptToolbox.com/checkboxgroup/
 
T

Thomas 'PointedEars' Lahn

Chuck said:
See below. For various serverside/database reasons the names of these
elements needs to be different: [HTML code]

I meant your approach of solving the problem with client-side JS that is
not working.


PointedEars
 
S

Safalra

Is there a way with javascript to make a series of checkboxes behave
like radio buttons, such that if someone attempts to check more than
one, they would get a pop-up alert "can't do that" ?

Why would you use checkboxes, which indicate to the user that more than one
can be selected, if you want them to behave like radio buttons? It seems a
rather perverse thing to do, like calling a submit button 'reset'.
 
C

Chuck W.

Matt this is perfect. Works just like I need if I do this:

<SCRIPT LANGUAGE="JavaScript">
<!-- \\
var fallGroup = new CheckBoxGroup();
fallGroup.addToGroup("fall*");
fallGroup.setControlBox("fallAll");
fallGroup.setMaxAllowed(1,"You may only select one Fall option!");
fallGroup.setMasterBehavior("some");
\\ -->

</SCRIPT>
<INPUT TYPE="hidden" NAME="fallAll" VALUE="ALL"
onClick="fallGroup.check(this)">

<input type=checkbox name=fall01 value="60"
onClick="fallGroup.check(this)"> $60.00

<input type=checkbox name=fall02 value="60"
onClick="fallGroup.check(this)"> $60.00
 
T

Thomas 'PointedEars' Lahn

Chuck said:
Matt this is perfect.

It's not. Perfect is a solution if it also works without
client-side scripting, just as input[type="radio"] elements do.
Works just like I need if I do this:

<SCRIPT LANGUAGE="JavaScript">
<!-- \\
[...]
\\ -->

What the heck is this?

1. the `language' attribute is deprecated in HTML4, the `type'
attribute is #REQUIRED: Use <script type="text/javascript">,
or, if you want to adhere to the now Informational RFC[1]
"Scripting Media Types", <script type="application/javascript">.

2. HTML comment delimiters (to more precise: SGML declarations
containing only comments) are `<!--' and `-->', not `<!-- \\
and `\\ -->' (there are no backslashes involved anyway,
single-line comments are introduced by `//' -- `\\' there
results in a script error).

3. It is an obsolete practice and considered harmful to try using
HTML comment delimiters to try to comment out `script' element
CDATA contents.


PointedEars
___________
[1] See
<http://www1.ietf.org/mail-archive/web/ietf-announce/current/msg01349.html>
 
C

Chuck W.

Good for you. Book smart.

Perfect for me is that it works for how I need it to work.

Thanks for your suggestions though.

Peace,

-Chuck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top