473,287 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

If I select a checkbox, I deactivate another

4
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

✓ answered by dev7060

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. }

2 30934
dev7060
626 Expert 512MB
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 Bit
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
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
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
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...
2
by: tvnaidu | last post by:
Why firefox doesn't remember userid and password eventhough I select checkbox "Remeber my login on this computer"?
1
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. ...
1
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...
5
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...
6
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
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.