473,597 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If I select a checkbox, I deactivate another

4 New Member
Here's the situation: As you can see in the visual example below. I have four - buttons radio - I need to make an event where when I select the option "NO" of the compo I automatically disable the two selections in the field .

If "YES" is selected, the two other selections must remain active. My problem is because the four stamps are "radio buttons" and not a checkbox.

Visual example:

<-- IVF fertilization -->

⬜ Yes ⬜ No

<-- if IVF ovum -->

⬜ Own ⬜ From a donor

I have this snippet:


Expand|Select|Wrap|Line Numbers
  1. Code 1
  2. Base PHP code I'm using.
  3.  
  4. <!-- IVF fertilization -->
  5. <div class='col-sm-4'>
  6.     <?=_('IVF fertilization')?>
  7.     <div>
  8.         <input type="radio" id="yesFe" name="niptData_ivfFertilization" value='1' 
  9.             <?=($_SESSION['REQUEST']['niptData_ivfFertilization-required0allow'] == '1' OR $registration->test->data->ivfFertilization == '1') ? 'checked' : ''?>
  10.         > 
  11.         <label for="yesFe" class='smallLabel'><?=_('Yes')?></label> 
  12.     </div>
  13.  
  14.     <div>
  15.         <input type="radio" id="noFe" name="niptData_ivfFertilization" value='0' 
  16.             <?=($_SESSION['REQUEST']['niptData_ivfFertilization-required0allow'] == '0' OR $registration->test->data->ivfFertilization == '0') ? 'checked' : ''?>
  17.         > 
  18.         <label for="noFe" class='smallLabel'><?=_('No')?></label> 
  19.     </div>
  20. </div>
  21.  
  22. <!-- if IVF ovum -->
  23. <div class='col-sm-4'>
  24.     <?=_('If IVF ovum')?>
  25.     <div>
  26.         <input type="radio" id="ownOv" name="niptData_ovum" value='1' data-validation="" 
  27.             <?=($_SESSION['OPTIONAL']['niptData_ovum'] == '1' OR $registration->test->data->ovum == '1') ? 'checked' : ''?>
  28.         > 
  29.         <label for="ownOv" class='smallLabel'><?=_('Own')?></label> 
  30.     </div>
  31.  
  32.     <div>
  33.         <input type="radio" id="fromADonor" name="niptData_ovum" value='2' data-validation="" 
  34.             <?=($_SESSION['OPTIONAL']['niptData_ovum'] == '2' OR $registration->test->data->ovum == '2') ? 'checked' : ''?>
  35.         > 
  36.         <label for="fromADonor" class='smallLabel'><?=_('From a donor')?></label> 
  37.     </div>
  38.     <br>
  39. </div>
  40.  
  41.  
  42.  
  43. CODE 2
  44. Script that working to solve the problem.
  45.  
  46.  
  47. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  48.                         <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
  49. <script>
  50.     $(document).ready(function () {
  51.         $('#new_user_form *').filter(':radio').change(function() {
  52.             if(this.id=='noFe' && this.value=='0' && $(this).is(':checked')) {
  53.                 $('#new_user_form *').filter(':radio').each(function(){
  54.                     if(this.id=='noFe' && this.value=='0') {
  55.                     } else {
  56.                         $(this).attr("checked",false);
  57.                     }
  58.                 });
  59.             }
  60.             if((this.id=='ownOv' || this.id=='fromADonor' && this.value=='0') {
  61.                 var checkedId = this.id;
  62.                 var checkedOrNot = $(this).is(':checked');
  63.                 $('#new_user_form *').filter(':radio').each(function(){
  64.                     if(this.id==checkedId && (this.value=='1' || this.value=='2')) {
  65.                         if(checkedOrNot) {
  66.                             $(this).attr("disabled",true);
  67.                         } else {
  68.                             $(this).attr("disabled",false);
  69.                         }
  70.                     }
  71.                 });
  72. </script>
  73.  
  74.  
  75.  
  76. CODE 3
  77. HTML code that was asked of me.
  78.  
  79.  
  80. <div class="col-sm-4">
  81.                 Pregnancy<span class="required">*</span>
  82.                 <div class="has-error">
  83.                 <input type="radio" id="yesFe" name="niptData_ivfFertilization-required0allow" value="1" data-validation="required" class="error" style="border-color: rgb(185, 74, 72);"> 
  84.                 <label for="yesFe" class="smallLabel">Yes</label> 
  85.                 <span class="help-block form-error">Required field</span></div>
  86.  
  87.                 <div class="has-success">
  88.                 <input type="radio" id="noFe" name="niptData_ivfFertilization-required0allow" value="0" data-validation="required" class="valid" style=""> 
  89.                 <label for="noFe" class="smallLabel">No</label> 
  90.                 </div>
  91.             </div>
  92.  
  93.  
  94. <div class="col-sm-4">
  95.                 if FIVET, ovum<span class="optional"></span>
  96.                 <div>
  97.                 <input type="radio" id="ownOv" name="niptData_ovum" value="1" data-validation=""> 
  98.                 <label for="ownOv" class="smallLabel">Own</label> 
  99.                 </div>
  100.  
  101.                 <div>
  102.                 <input type="radio" id="fromADonor" name="niptData_ovum" value="2" data-validation=""> 
  103.                 <label for="fromADonor" class="smallLabel"> 
  104. As a donor</label> 
  105.                 </div>
  106.                 <br>
  107.             </div>
  108.  
Oct 21 '21 #1
2 30954
dev7060
644 Recognized Expert Contributor
Here's the situation: As you can see in the visual example below. I have four - buttons radio - I need to make an event where when I select the option "NO" of the compo I automatically disable the two selections in the field .

If "YES" is selected, the two other selections must remain active. My problem is because the four stamps are "radio buttons" and not a checkbox.

Visual example:

<-- IVF fertilization -->

⬜ Yes ⬜ No

<-- if IVF ovum -->

⬜ Own ⬜ From a donor
HTML
Expand|Select|Wrap|Line Numbers
  1. <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  2. <form>
  3.     <h3> IVF fertilization </h3>
  4.     <input type="radio" name="fertilization" id="radio_1">yes <br>
  5.     <input type="radio" name="fertilization" id="radio_2">no <br>
  6.     <h3> if IVF ovum </h3>
  7.     <input type="radio" name="ovum" class="group1" disabled>Own <br>
  8.     <input type="radio" name="ovum" class="group1" disabled>From a donor <br>
  9. </form>
JS
Expand|Select|Wrap|Line Numbers
  1. $(function() {
  2.     $("#radio_1").click(yes);
  3.     $("#radio_2").click(no);
  4.  
  5. });
  6.  
  7. function yes() {
  8.     if (this.checked) {
  9.         $("input.group1").removeAttr("disabled");
  10.     }
  11. }
  12.  
  13. function no() {
  14.     if (this.checked) {
  15.         $("input.group1").attr("disabled", true);
  16.         $("input.group1").attr("checked", false);
  17.     }
  18. }
Oct 22 '21 #2
locoge
1 New Member
If I select a checkbox Thank s link
Dec 6 '21 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2688
by: find clausen | last post by:
qqq = GetCookie("whatever"); How do I select a chekbox in a form if qqq = yes TIA -- find clausen press photos from denmark www.photopress.dk
2
2482
by: ASAP | last post by:
there is a checkbox in every row of a table. i need to check the checkbox on click of the corresponding row and vice -versa. means on again clicking of the same row it should get delected.
1
1786
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below ------------------------------------------------------------------------ "Commercial Security Middle East, Homeland Security and Policing Middle East,Safety & Health Middle East, "...
2
1762
by: tvnaidu | last post by:
Why firefox doesn't remember userid and password eventhough I select checkbox "Remeber my login on this computer"?
1
1551
by: Rodney Ferguson | last post by:
Hi, I'm programming a questionnaire but I'm having trouble with some checkboxes. I would like to have the user select or deselect the checkbox by clicking on the table cell that it is in. Rodney
1
1540
by: Adewunmi Agbato | last post by:
I just developing my web design skills. I have a Datagrid with 2 textbox template columnsand two checkbox template columns. I have two other Textbox controls and two CheckBox controls. I have an Add button. I want to be able to use the add button to update Datagrid Record inserting the Textbox control texts and the Checkbox Control status. Any Help? Thanks
5
2217
by: Sindhu Kumar | last post by:
I hav a jsp page whch dynamically displays the records from database into table. On the left side of each row in a table i use checkbox for users to select for deleting single/multiple records from database.. if database contains muliple records i can easily check the checkboxes of required rows in a table and delete thm from database.. But i can't select a checkbox in a table if database contains exactly one record.. Help me plz.. it's...
6
1432
by: msingh24 | last post by:
I have 2 forms and I want to grey out a checkbox or option button in the 2nd form when one checkbox/optionbutton is selected in this 1st form Please HELP!! Thanks
1
952
by: macmiller6578 | last post by:
Hi currently I am working on trying to count whether a particular tutor is male or female. I have a table that has gender information and I want to count when a checkbox is checked saying they are an active tutor in a query. I'm very new with this stuff so bear with me...this is my code currently-> MaleTutor: (select IIf(Tbl_TutorInfo.=True , (Count(IIf(=”Male”,0)) from (select from tbl_tutorinfo inner join tbl_tutorplace ...
0
7959
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8263
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5842
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2393
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.