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
Solved

CheckBox - onchange event?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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