MattsBits
MattsBits

MattsBits

Yes No Checkboxes With Automatic Uncheck  

by Matt Hawkins, 11/06/2009
Categories : JavaScript

The following article explains how to create sets of Yes No checkboxes that are mutually exclusive. That is when you check the Yes box the corresponding No box is unchecked.

The HTML below shows how this can be achieved :

<html>
<head><title></title></head>
<body>

<script language="JavaScript">
<!-- Begin
function CheckBoxesByName(sName,sMode)
{


At this point you need to insert the CheckBoxesByName function definition from the Check, Uncheck And Toggle Checkboxes By Name page

}
//  End -->
</script>

<p>
Yes<input type="checkbox" checked="yes" name="cbox_yes_1"
      onchange="CheckBoxesByName('cbox_no_1',2)">
No<input type="checkbox" name="cbox_no_1"
     onchange="CheckBoxesByName('cbox_yes_1',2)"></p>

<p>
Yes<input type="checkbox" checked="yes" name="cbox_yes_2"
      onchange="CheckBoxesByName('cbox_no_2',2)">

No<input type="checkbox" name="cbox_no_2"
     onchange="CheckBoxesByName('cbox_yes_2',2)"></p>

<p>
Yes<input type="checkbox" checked="yes" name="cbox_yes_3"
      onchange="CheckBoxesByName('cbox_no_3',2)">
No<input type="checkbox" name="cbox_no_3"
     onchange="CheckBoxesByName('cbox_yes_3',2)"></p>

</body>
</html>


If you want to see the script in action then click the example file below.

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2017