Solved

CheckBox - onchange event?

Posted on 2006-06-20
2
1,962 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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