473,413 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Make checkboxes act like radiobuttons?

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

Nov 11 '05 #1
8 2737
Chuck W. wrote:
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
Nov 11 '05 #2
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>

Nov 11 '05 #3
Chuck W. wrote:
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
Nov 11 '05 #4
Chuck W. wrote:
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/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 11 '05 #5
On 11 Nov 2005 06:36:21 -0800, Chuck W. wrote:
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'.

--
Safalra (Stephen Morley)
http://www.safalra.com/programming/javascript/
Nov 11 '05 #6
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

Nov 11 '05 #7
Chuck W. wrote:
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>
Nov 11 '05 #8
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

Nov 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: LRW | last post by:
I did a Web search, and a deja.com search on this...and I'm finding how to make checkboxes act like radiobuttons, and other interesting behaviors, but nothing that quite answers my question. If...
4
by: James Greig | last post by:
hello people, i'm just learning javascript, could someone point me in the direction of an example of the following, or give me some clues as to how it might be done: what i would like to do...
4
by: BjoernJackschina | last post by:
HEllo, I still have always the same problem with a no object form in my source code. It is for checking out used radiobuttons or checkboxes.<script <!-- function pruefen(){return true} -->...
2
by: JohnK | last post by:
Hi all, This is my first time visiting this group. I already tried two other java groups, but those aren't very populated. I don't know if it is the right one, otherwise please tell me in which...
1
by: Miguel Orrego | last post by:
Hi, I have a form that is created dynamically from a recordset, this creates a line for each record together with 2 checkboxes, Yes & No so the source output would be something like this: ...
1
by: Patrick | last post by:
Hello - I am designing a form that only allows 2 checkboxes to be checked out of a series of checkboxes. However, checkedchanged and checkstatechanged both act when the box is clicked on. I want...
4
by: Dabbler | last post by:
Not sure what SQL datatype should be used with radiobuttons since MS SQL doesn't support a boolean datatype. I would like to bind radiobuttons to an SqlDataSource. Thanks for any suggestions on...
0
by: PaulS | last post by:
Hello! I put on Form PictureBox and I set big image. Next I put many radiobuttons (80) on PictureBox, but I have problem. I want that 10 radiobuttons have own Checked, next part of 10...
7
by: harikap | last post by:
hi , here im using vb.net 2005how can i add radiobuttons as column to windows datagridview control plz help me....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.