473,394 Members | 1,735 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,394 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 30943
dev7060
636 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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.