Solved

CheckBox - onchange event?

Posted on 2006-06-20
2
1,961 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
kGenius earned 500 total points
ID: 16945916
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
ID: 16951749
Wonderful!

Thank you!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

737 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