JavaScript Find radio and checkbox name using surrounding labeltext with Jquery

I'm trying to accomplish the following with Jquery:

When the "No Top" radio-button is "checked" it should disable and "uncheck" any selection done in the Checkbox selection.

If the user select another radio-button option for example "Black Top", the Checkbox selection should be enabled again.

I'm trying to solve this problem but can't figure out how to find the correct radio-button or checkbox using the labels text (that's all I have to go on). I can't use the ID's because it renders with different names all the time.

Clarification: The first div class "option-box" contains the radio set which then follows a second div class "option-box" with the checkboxes. The page have more controls both radio and checkboxes but it is just the checkboxes inside the second "option-class" I'm trying to manipulate.

Any ides?

Here is the code that my controls generate (which I cant modify):

<div class="option-box">
    <div class="radio">
        <label>
            <input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_0" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="0" checked="checked" type="radio" />
            No Top
        </label>
    </div>
    <div class="radio">
        <label>
            <input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_1" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="8" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4$1\',\'\')', 0)" type="radio" />
            Black Top
        </label>
    </div>
    <div class="radio">
        <label>
            <input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_2" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="9" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4$2\',\'\')', 0)" type="radio" />
            White Top
        </label>
    </div>
    <div class="radio">
        <label>
            <input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_3" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="10" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4$3\',\'\')', 0)" type="radio" />
            Silver Top
        </label>
    </div>
</div>

<div class="option-box">
    <div class="checkbox">
        <label>
            <input id="ctl00_PageContent_ctl00_KitsList_ctl04_KitComponent_10_0" name="ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$0" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$0\',\'\')', 0)" value="11" type="checkbox" />
            Backdoor
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input id="ctl00_PageContent_ctl00_KitsList_ctl04_KitComponent_10_1" name="ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$1" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$1\',\'\')', 0)" value="12" type="checkbox" />
            Topdoor
        </label>
    </div>
</div>
Answer:1

You can differentiate the inputs by their type attribute, something like this:

$('.option-box input[type="radio"]').change(function() {
    $('.option-box input[type="checkbox"]').prop({
        'disabled': $(this).val() == "0", 
        'checked': false
    });
});

Example fiddle

If there are multiple copies of this .option-box structure in the page you can use DOM traversal to find the one related to that which raised the event:

$('.option-box input[type="radio"]').change(function() {
    $(this).closest('.option-box').next('.option-box').find('input[type="checkbox"]').prop({
        'disabled': $(this).val() == "0", 
        'checked': false
    });
});

Example fiddle

Answer:2

If you cannot use any id nor the input VALUE, you can try like this

$(document).ready(function () {
  $( '.option-box' ).on( 'click', 'input[type="radio"]', function() {
    var labelContent = $( this ).parents(".radio").find( "label" ).html();
    if( labelContent.indexOf( "No Top" ) > -1 ) {
      $( ".checkbox input" ).attr( "disabled", "disabled" ).removeAttr( "checked" );
    } else {
      $( ".checkbox input" ).removeAttr( "disabled" );
    }
  });
});
Answer:3

I want to create paragraph dynamic,so I wrote the following code. After user click the button, a new paragraph whose innerText is the user's inputs should be added.But I failed, Is there someone can ...

I want to create paragraph dynamic,so I wrote the following code. After user click the button, a new paragraph whose innerText is the user's inputs should be added.But I failed, Is there someone can ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I'm trying to create a news style marquee at the bottom of my XSL page that shows some information it retrieves from an XML file. What I want it to do is automatically refresh the content of only this ...

I'm trying to create a news style marquee at the bottom of my XSL page that shows some information it retrieves from an XML file. What I want it to do is automatically refresh the content of only this ...

  1. reload iframe content using javascript
  2. reload div content using javascript
  3. reload div content using ajax
  4. reload a div content using jquery
  5. reload content using javascript
  6. reload content using ajax
  7. javascript reload iframe content
  8. reload iframe from javascript
  9. how to reload iframe in javascript

I have an array of letters and numbers. let sortLetters = [ 'R', '1', 'U', '1', 'N', '1', 'D', '1', 'M', '1', 'C', '1' ] I want to sort the types alphabetically, then return the first letter I come ...

I have an array of letters and numbers. let sortLetters = [ 'R', '1', 'U', '1', 'N', '1', 'D', '1', 'M', '1', 'C', '1' ] I want to sort the types alphabetically, then return the first letter I come ...

Hello I am taking an array of integers with ranging numbers from 1 - 100 and I'm counting the duplicated numbers within it. Example, array[1,1,1,1,1,100,3,5,2,5,2,23,23,23,23,23,]. Result = 1 - 5 ...

Hello I am taking an array of integers with ranging numbers from 1 - 100 and I'm counting the duplicated numbers within it. Example, array[1,1,1,1,1,100,3,5,2,5,2,23,23,23,23,23,]. Result = 1 - 5 ...

  1. find duplicate count in excel
  2. find duplicate count in sql
  3. find duplicate count in list java
  4. find duplicate count in array
  5. find duplicate count in list c#
  6. find duplicate count in java
  7. find duplicate count in oracle
  8. count find duplicate rows
  9. find count of duplicate rows in sql
  10. find count of duplicate values in excel
  11. find count of duplicate values in list java
  12. find count of duplicate number in array
  13. find count of duplicate values in sql
  14. excel find duplicate count if
  15. how to find duplicate count in array in java
  16. how to find duplicate count in arraylist
  17. how to find duplicate count in excel using formula
  18. how to find duplicate count in mysql
  19. formula to find duplicate count in excel