Solved

CheckBox - onchange event?

Posted on 2006-06-20
2
1,955 Views
Last Modified: 2010-08-05
Hi all!

I have a HUGE form (over 250 fields) which contains just about every type of input your could imagine.

The customer would now like to have two of the checkboxes on the form be relative to each other...they'd be performing more like radio buttons, in that if one is checked, the other will uncheck.

I don't think I can do an autopostback, because I don't want the form submitted until all the values are completed and these checkboxes are in the middle of the page.

Can anyone show me a function that I can apply to an onchange event that will check to make sure that if Checkbox1 is selected then Checkbox2 isn't and vice-versa?

Thanks!
0
Comment
Question by:ClassyLinks
2 Comments
 
LVL 7

Accepted Solution

by:
kGenius earned 500 total points
Comment Utility
add this script to your html head

<script type="text/javascript">
function ReverseCheckBox(sender, linkedControl) {
if (document.getElementById(sender).checked==true) {
document.getElementById(linkedControl).checked = ! document.getElementById(sender).checked;
}
}
</script>

You must add in code behind the attribute:
onclick="ReverseCheckBox('THE ID OF THE CHECKBOX', 'THE ID OF THE LINKED CHECKBOX');" to every checkbox

your output must become something like:
 <asp:CheckBox ID="CheckBox1" runat="server" onclick="ReverseCheckBox('CheckBox1', 'CheckBox2');"/>
 <asp:CheckBox ID="CheckBox2" runat="server"  onclick="ReverseCheckBox('CheckBox2', 'CheckBox1');"/>

kGenius
0
 
LVL 7

Author Comment

by:ClassyLinks
Comment Utility
Wonderful!

Thank you!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now