473,327 Members | 2,094 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,327 software developers and data experts.

Unchecking two items in a checkboxlist?

Hi,
I need to tell a checkbox list that if two of the items have been checked,
to uncheck themselves. I need help! Thanks :)

~Chelimar
Nov 18 '05 #1
2 1458
It sounds like you may want to switch to a RadioButtonList, then.
That's the default behavior of a radio button group (selecting one
deselects the previous).

Two benefits:
1. Less code for you to write, debug, and maintain
2. Standard HTML form behavior so your users will not be confused. A
checkbox list _should_ allow multiple selections according to the HTML
specs.

If you're stuck with this due to business requirements (I've been
there, too), you'll have to do this with Javascript on the client.
Here's some sample code to get you started (needs to be converted to a
webform):

<html>
<head>
<script>
function VerifyCheckboxes()
{
count = document.frm1.elements.length;
checkedElements = 0;
for (i=0; i < count; i++)
{
if(document.frm1.elements[i].checked == 1)
{
checkedElements++;
if(checkedElements>1)
{
uncheckAll();
}
}
}
}

function uncheckAll()
{
for (i=0; i < count; i++)
{
document.frm1.elements[i].checked = 0;
}
}
</script>
</head>
<body>
<form name="frm1">Sample
<input type="checkbox" onclick="VerifyCheckboxes()" value="1"/>
<input type="checkbox" onclick="VerifyCheckboxes()" value="2"/>
<input type="checkbox" onclick="VerifyCheckboxes()" value="3"/>
<input type="checkbox" onclick="VerifyCheckboxes()" value="4"/>
<input type="checkbox" onclick="VerifyCheckboxes()" value="5"/>
</form>
</body>
</html>

Nov 18 '05 #2
Write one method which does this work and attach it to onclicked
eventhandler of both the checkbox.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Chelimar" <Ch******@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
Hi,
I need to tell a checkbox list that if two of the items have been checked,
to uncheck themselves. I need help! Thanks :)

~Chelimar

Nov 18 '05 #3

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

Similar topics

2
by: EnjoyLife | last post by:
I am new to ASP.NET and am trying to learn it the best that I can. I am trying to add some code in the If IntRowIndex > -1 statement to mark an item SELECTED before adding it to the CheckBoxList. ...
2
by: Bart Van Hemelen | last post by:
The situation: I have a CheckBoxList cblTest, the items are disabled in cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop. I provide a link that calls a client-side JavaScript...
0
by: jeremy | last post by:
Had a tough time figuring this one out and couldn't find a good solution, so I thought I would post this and hopefully it will help someone out. When using DataBind to dynamically bind a list to...
3
by: onlyprad | last post by:
Hi, I am populating the checkboxlist in (!IsPostBack) block of page load event with some checked items. After populating with checked items I am iterating through the items collection and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.